2016-08-22 44 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)的情況下