从其他活动调用活动导致黑屏

时间:2021-01-05 10:31:17

标签: android android-intent android-activity

        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()

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

被调用的活动:

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" />

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

1 个答案:

答案 0 :(得分:0)

使用标志 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 传递给(现在位于顶部)旧活动作为新意图。

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

如果您使用 <item name="android:windowBackground">@android:color/transparent</item>,活动的默认主题将显示为黑屏,也称为“预览”。

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

相关问题