在我來說,我一直在使用startActivityForResult調用活動B的活性的。TaskStackBuilder與startActivityForResult
活動B是返回數據到活性的因而數據可被存儲在我的數據庫的形式。
而且,我的應用程序啓動一下,當我嘗試去從活動B返回到活動A,因爲該方法「onActivityResult」永遠不會被調用時我的問題時開始活動B的通知。我不能夠模擬startActivityForResult()當我創建我TaskStackBuilder:
Intent resultIntent = new Intent(this, activityB.class);
// This ensures that navigating backward from the Activity leads out of your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(activityB.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setContentIntent(resultPendingIntent);
最後,我添加了活性B中的父活動在manifest.xml:
<activity
android:name=".activityB"
android:parentActivityName=".activityA"
android:windowSoftInputMode="stateHidden">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activityA"/>
</activity>