Refer this link :
http://developer.android.com/guide/topics/ui/notifiers/notifications.html#NotificationResponse
首先定義活動層級在AndroidManifest.xml用於發射 activity.Also建立你通知如下:
<activity
android:name=".LauncherActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ResultActivity"
android:parentActivityName=".LauncherActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".LauncherActivity"/>
</activity>
Intent resultIntent=new Intent(this,ResultActivity.class);
TaskStackBuilder stackBuilder=TaskStackBuilder.create(this);
stackBuilder.addParentStack(ResultActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent=stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder=new NotificationCompat.Builder(this);
builder.setContentIntent(resultPendingIntent);
NotificationManager mNotif`enter code here`icationManager=
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(id,builder.build());
你可以使用一個布爾共享prefrences和處理你的場景或可以實現onbackPressed和處理你的場景 –
@UsurKurd謝謝,是的,你是對的我在所有活動中處理'onbackpress'事件,但我想要任何其他解決方案,如果可能的話來處理這種情況 –
處理與共享prefü可以使用,以及 –