在我的例子中,我有一个活动A,它使用startActivityForResult调用活动B.
活动B是将数据返回到活动A的表单,因此数据可以存储在我的数据库中.
此外,我的应用程序启动通知,单击时启动活动B,当我尝试从活动B返回到活动A时出现问题,因为从未调用方法"onActivityResult".在创建TaskStackBuilder时,我无法模拟startActivityForResult():
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);
Run Code Online (Sandbox Code Playgroud)
最后,我在manifest.xml中添加了活动B的父活动:
<activity
android:name=".activityB"
android:parentActivityName=".activityA"
android:windowSoftInputMode="stateHidden">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activityA"/>
</activity>
Run Code Online (Sandbox Code Playgroud)