2014-02-18 34 views
0

這是我如何把它從一個活動發送ApplicationInfo另一個

 Intent i = new Intent(v.getContext(), Permissions.class); 
     i.putExtra("AppSelected",installedApps.get((int) id)); 
     startActivity(i); 

這是我如何找回它:

 Bundle extras = getIntent().getExtras(); 
     ApplicationInfo a = extras.get[What do I put here?]("AppSelected"); 

我似乎無法找出得到這個工作。有什麼想法嗎?

+0

ApplicationInfo是' Parcelable'? –

+1

@ρяσѕρєяK:其實,它是 - 我需要自己去看看。 – CommonsWare

+0

我似乎無法得到任何這些工作。 爲了更簡單地說明我的問題,我想採用ApplicationInfo的實例並在其他活動中使用它的字段。 – UserK

回答

0

呼叫getParcelable()檢索您ApplicationInfo(它實現Parcelable接口)。您需要將結果轉換爲ApplicationInfo

+0

你能詳細說明一下這個意思嗎? getParcelable()是否獲取整個應用程序對象? – UserK

+0

@ user3293569:「getParcelable()是否獲取整個應用程序對象?」 - 是的,無論「ApplicationInfo」的實現認爲「整個應用程序對象」是什麼。 – CommonsWare

0

假設installedApps.get...返回一個整數,你應該在Bundle更改代碼

Bundle extras = getIntent().getExtras(); 

int appId = getIntent().getIntExtra("AppSelected", 0); 
0

檢索任何額外只需使用您用來保存值密鑰加上默認在某些情況下,例如

Bundle extras = getIntent().getExtras(); 
    int example = extras.getIntExtra("key", int defaultValue) ;//to retrieve an Integer 
    String example = extras.getStringExtra("key"); //to retrieve a String 

.....兒子等等

in your case 
    Bundle extras = getIntent().getExtras(); 
    ApplicationInfo a = extras.getIntExtra("AppSelected", 0); 
相關問題