在我的情况下,我有一个名为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);
最后,我在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>