我在使用收到的通知的待定意图时如何启动 DetailActivity 时遇到一些问题 当应用程序在后台运行时,它总是启动 MainActivity (但是当应用程序在前台运行时,它可以正常工作)
每个人都可以帮助我,对我英语不好的情况感到抱歉
notificationIntent
val intent = Intent(this, DetailActivity::class.java)
intent.action = Intent.ACTION_MAIN
intent.addCategory(Intent.CATEGORY_LAUNCHER)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
PendingIntent
val pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT)
manifest.xml
<application
android:name=".helper.App"
android:icon="@drawable/ic_main_app"
android:label="@string/app_name"
android:roundIcon="@drawable/ic_main_app"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning"
tools:targetApi="m">
<activity
ndroid:screenOrientation="portrait"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"
android:name=".ui.activity.aduan.DetailActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="kominfo.com.umat.ui.activity.main.MainActivity"/>
</activity>
<activity
android:screenOrientation="portrait"
android:name=".ui.activity.main.MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
答案 0 :(得分:0)
您已将DetailActivity
中的Manifest
设置为
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="kominfo.com.umat.ui.activity.main.MainActivity"/>
这就是您的DetailActivity
需要MainActivity
还尝试将以下标志添加到您的意图中
Intent.FLAG_ACTIVITY_CLEAR_TOP
Intent.FLAG_ACTIVITY_SINGLE_TOP
和Notification
notification.flags |= Notification.FLAG_AUTO_CANCEL