【问题标题】:Calling Activity from other activity leading to black screen从其他活动调用活动导致黑屏
【发布时间】:2021-01-05 10:31:17
【问题描述】:
        val callIntent = Intent(this, AcsActivity::class.java)
        //callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        callIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or  Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
        startActivity(callIntent)
        finish()

点击此代码后,屏幕变黑,如果我在最近的应用中看到此应用,它会显示正确的 UI。

调用的活动:

class AcsActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_acs)
    }
}

调用的活动界面

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="org.jio.meet.conference.view.activity.AcsActivity">

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

调用的活动清单条目:

        <activity android:name="org.jio.meet.conference.view.activity.AcsActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"/>

调用活动清单条目:

        <activity
            android:name="org.jio.meet.dashboard.view.activity.StartMeetingActivity"
            android:configChanges="locale|orientation|screenSize"
            android:label=""
            android:launchMode="singleTop"
            android:theme="@style/AppTheme" />

不知道这里出了什么问题,请您帮忙吗?

【问题讨论】:

    标签: android android-intent android-activity


    【解决方案1】:

    使用标志FLAG_ACTIVITY_CLEAR_TOPFLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 将隐藏当前已经运行的活动。因此,显示黑屏。

    根据Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS的Android文档:

    如果设置,新活动不会保留在最近启动的活动列表中。

    根据Intent.FLAG_ACTIVITY_CLEAR_TOP的Android文档:

    如果设置了,并且正在启动的 Activity 已经在当前任务中运行,那么不会启动该 Activity 的新实例,而是关闭它之上的所有其他 Activity,并且此 Intent 将被传递到(现在在顶部)作为新 Intent 的旧活动。

    如果不需要某些特殊功能,则不能使用标志来启动 Activity。

    如果您使用&lt;item name="android:windowBackground"&gt;@android:color/transparent&lt;/item&gt;,活动的默认主题将显示为黑屏,即“预览”。

    您应该将窗口背景设置为透明以外的颜色。无需在xml文件中设置背景即可解决问题。

    【讨论】:

    • 我删除了标志,但仍然是同样的问题。当我在 xml 文件中将背景设置为白色时,问题得到解决。 android:background="@color/White" 你明白这里可能是什么问题吗?
    • 您是否更改了 AppTheme 中的任何内容?
    • AppTheme 中的@TarunChawla,你使用android:windowBackground 还是同样的东西?
    • ​​@android:color/transparent,设置为透明。 @Tungken
    • @TarunChawla 您应该将窗口背景设置为透明以外的颜色。在xml文件中不设置背景,问题将得到解决。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    • 2016-01-25
    • 2011-02-17
    • 2019-07-25
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    相关资源
    最近更新 更多