2016-08-22 73 views
2

在我来说,我一直在使用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> 

回答

2

由于我对Android的框架的知识,当活动已经开始用startActivityForResult()方法和相应的活动已叫的setResult一个OnActivityResult方法只调用。

Android的官方文档Android TaskStackBuilder:构建合成回栈交任务导航

的实用工具类

所以我不认为你可以说该框架回去使用该回调的活动。

相反,你可以做的是在Intent中放置一些额外的内容,然后当你回到后面的堆栈中(对于活动A)时,检查初始方法(onCreate或onResume)内部的额外或参数,它们只会是有在从最后正在添加的活性(活性B)的情况下