0
代碼開放活動B之後從廣播接收器返回主實際上從通知
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(G.context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(G.context.getString(R.string.app_name))
.setContentText("text")
.setAutoCancel(true)
.setColor(Color.MAGENTA);
Intent intent = new Intent(G.context, B.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(G.context);
taskStackBuilder.addParentStack(MainActivity.class);
taskStackBuilder.addNextIntent(intent);
PendingIntent resultPendingIntent = taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) G.context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(2, mBuilder.build());
感謝 用這種方法,當我打開從應用的B活性,並把返回鍵按鈕,新創建的活動主要這是不對的。我認爲 – alipro
它可能通過調用簡單的'onBackPressed()'方法也可以'this.finish()',但如果沒有任何以前的活動堆棧可用,那麼應用程序將被關閉 – Shailesh
當我們調用B活動時,這應該不會發生程序 也就是說,你不應該從主要活動中創建一個實例 還有其他方法嗎? – alipro