2012-12-06 67 views
0

我開發了一個應用程序,其中包含一個主屏幕與文章列表。 如果您點擊它,您將訪問另一個屏幕中的詳細信息。安卓導航按鈕上果凍豆

我實現了ActionBarSherlock,所以我使用了「向上」按鈕模式進行此活動。

然後我給這個應用程序添加了一個小部件。當你點擊小部件時,你直接訪問細節活動。

「向上」按鈕已按照Google推薦(http://developer.android.com/training/implementing-navigation/ancestral.html)執行。

我的問題是,在API級別15及以下,它完美的作品。它調用下面的代碼:

@Override 
public boolean shouldUpRecreateTask(Activity activity, Intent targetIntent) { 
    String action = activity.getIntent().getAction(); 
    return action != null && !action.equals(Intent.ACTION_MAIN); 
} 

但在豆形軟糖,使用的代碼是:

public boolean shouldUpRecreateTask(Intent targetIntent) { 
    try { 
     PackageManager pm = getPackageManager(); 
     ComponentName cn = targetIntent.getComponent(); 
     if (cn == null) { 
      cn = targetIntent.resolveActivity(pm); 
     } 
     ActivityInfo info = pm.getActivityInfo(cn, 0); 
     if (info.taskAffinity == null) { 
      return false; 
     } 
     return !ActivityManagerNative.getDefault().targetTaskAffinityMatchesActivity(mToken, info.taskAffinity); 
    } catch (RemoteException e) { 
     return false; 
    } catch (NameNotFoundException e) { 
     return false; 
    } 
} 

方法的第一部分檢索。如果堆棧必須重新創建應加載的活動信息。

但我還是不明白什麼是行:

!ActivityManagerNative.getDefault().targetTaskAffinityMatchesActivity(mToken, info.taskAffinity); 

誰能幫助我在這條線,我真的需要找出如何初始化一切順利獲得正確的?

回答

0

它是一個布爾方法,它必須返回一些東西。如果它需要返回一個真正的布爾變量,它必須這樣做!

從官方文檔:

Returns true if the app should recreate the task when navigating 'up' 
from this activity by using targetIntent. 

If this method returns false the app can trivially call navigateUpTo(Intent) 
using the same parameters to correctly perform up navigation. 
If this method returns false, the app should synthesize a new task stack by using 
TaskStackBuilder or another similar mechanism to perform up navigation. 

的親和力表示活動更喜歡哪個任務屬於。默認情況下,來自同一個應用程序的所有活動都相互關聯。因此,默認情況下,同一應用程序中的所有活動都喜歡處於相同的任務中。但是,您可以修改某個活動的默認關聯。在不同應用程序中定義的活動可以共享一個關聯,或者可以爲同一個應用程序中定義的活動分配不同的任務關聯。

+0

我需要關於特定代碼的信息,該代碼返回true或false,以便能夠爲正確的情況創建正確的意圖。對我來說,你的答案是空的,當然,如果一個方法需要返回一個布爾值,你必須返回一個布爾值... – Seynorth

+0

再次檢查我的答案。我從官方文檔添加了東西! – Pavlos

+0

我也編輯了我的問題。我知道該方法的目標是什麼,我解釋說我將它用於上行導航模式。我唯一的問題是如何很好地初始化我的意圖或清單或任何其他文件來獲得「真正」的價值。 – Seynorth