Android意图-活动未恢复
我无法恢复活动 发生的情况如下: 活动A调用活动B:Android意图-活动未恢复,android,android-intent,Android,Android Intent,我无法恢复活动 发生的情况如下: 活动A调用活动B: Intent intent = new Intent(A.this, B.class); startActivity(intent); Intent intent = new Intent(this, MrpCastPlayerActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); Pendin
Intent intent = new Intent(A.this, B.class);
startActivity(intent);
Intent intent = new Intent(this, MrpCastPlayerActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
intent, 0);
android.support.v4.app.NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
notif.setContentIntent(pendingIntent)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("TITLE")
.setContentText("CONTENT")
.setAutoCancel(true);
notif.setOngoing(true);
Notification notification = notif.build();
NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationmanager.notify(0, notification);
Intent intent2 = new Intent(B.this, A.class);
startActivity(intent2);
然后活动B设置通知并调用活动a:
Intent intent = new Intent(A.this, B.class);
startActivity(intent);
Intent intent = new Intent(this, MrpCastPlayerActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
intent, 0);
android.support.v4.app.NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
notif.setContentIntent(pendingIntent)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("TITLE")
.setContentText("CONTENT")
.setAutoCancel(true);
notif.setOngoing(true);
Notification notification = notif.build();
NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationmanager.notify(0, notification);
Intent intent2 = new Intent(B.this, A.class);
startActivity(intent2);
问题是当我点击通知时,它会打开活动B,但它不会调用onResume
它会调用onCreate
。
如果我使用moveTaskToBack(true)
,而不是启动intent2
,则调用onResume
。
当我使用intent2
打开活动A时,活动B似乎已完成有办法避免这种情况吗?要继续您的活动,您应该考虑在您的
意图中添加标志
在onResume()和onstart()方法中不执行任何操作返回此活动时,请尝试以下操作
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
清单更改:
<activity android:name=".MyActivity"
android:configChanges="keyboardHidden|orientation">
希望这有帮助“它打开了活动B,但没有继续”-您能提供更多关于活动B的信息吗this@Libin它打开活动,但不调用onResume,而是调用onCreatecan-you-post您的清单。活动B android:launchMode应为“singleTop”是@Libin,设置了android:launchMode=“singleTop”。您可以发布如何创建PendingEvent实例吗?