【发布时间】:2016-08-22 08:53:23
【问题描述】:
在我的例子中,我有一个活动 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>
【问题讨论】:
-
您找到了完美的方法吗?我也有同样的场景
-
一点也不!只是解决方法,但这不是一件容易的事。对不起!