从其他 activity 调用 Activity 导致黑屏
Calling Activity from other activity leading to black screen
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。
被称为Activity:
class AcsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_acs)
}
}
叫 Activity UI
<?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 清单条目:
<activity android:name="org.jio.meet.conference.view.activity.AcsActivity"
android:configChanges="keyboardHidden|orientation|screenSize"/>
正在调用 activity 清单条目:
<activity
android:name="org.jio.meet.dashboard.view.activity.StartMeetingActivity"
android:configChanges="locale|orientation|screenSize"
android:label=""
android:launchMode="singleTop"
android:theme="@style/AppTheme" />
我不确定这里出了什么问题,你能帮忙吗?
使用标志 FLAG_ACTIVITY_CLEAR_TOP
和 FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
将隐藏当前已经 运行 activity。因此,显示黑屏。
根据 Android Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 的文档:
If set, the new activity is not kept in the list of recently launched activities.
根据 Android 文档 Intent.FLAG_ACTIVITY_CLEAR_TOP :
If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.
如果不需要某些特殊功能,则不能使用标志来启动 Activity。
如果您使用 <item name="android:windowBackground">@android:color/transparent</item>
,activity 的默认主题显示为黑屏,即 'Preview'。
您应该将 window 背景设置为透明以外的颜色。无需在 xml 文件中设置背景即可解决问题。
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。
被称为Activity:
class AcsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_acs)
}
}
叫 Activity UI
<?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 清单条目:
<activity android:name="org.jio.meet.conference.view.activity.AcsActivity"
android:configChanges="keyboardHidden|orientation|screenSize"/>
正在调用 activity 清单条目:
<activity
android:name="org.jio.meet.dashboard.view.activity.StartMeetingActivity"
android:configChanges="locale|orientation|screenSize"
android:label=""
android:launchMode="singleTop"
android:theme="@style/AppTheme" />
我不确定这里出了什么问题,你能帮忙吗?
使用标志 FLAG_ACTIVITY_CLEAR_TOP
和 FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
将隐藏当前已经 运行 activity。因此,显示黑屏。
根据 Android Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 的文档:
If set, the new activity is not kept in the list of recently launched activities.
根据 Android 文档 Intent.FLAG_ACTIVITY_CLEAR_TOP :
If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.
如果不需要某些特殊功能,则不能使用标志来启动 Activity。
如果您使用 <item name="android:windowBackground">@android:color/transparent</item>
,activity 的默认主题显示为黑屏,即 'Preview'。
您应该将 window 背景设置为透明以外的颜色。无需在 xml 文件中设置背景即可解决问题。