2014-04-12 140 views
0

我无法恢复活动。Android意图 - 未恢复活动

这里是发生了什么:

活动A调用活动B:

Intent intent = new Intent(A.this, B.class); 
startActivity(intent); 

然后活动B设置一个通知,并调用活动答:

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。 看来,活动B完成时,我用intent2打开活动A
是否有避免这种情况?

+0

“它打开活动B,但它不恢复它“ - 你能提供更多的信息在这 – Libin

+0

@利宾它打开活动,但不呼吁onResume,它的调用onCreate –

+0

你可以发布你的清单吗? Activity B android:launchMode应该是“singleTop” – Libin

回答

0

要恢复您的活动,您应该考虑将标记添加到您的Intent

方法做的onResume()和的OnStart()回来这个活动的时候,试试这个

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

舱单更改里面什么:

<activity android:name=".MyActivity" 

       android:configChanges="keyboardHidden|orientation"> 

希望这有助于