2012-03-14 71 views
0

我有問題要與意圖工作。調試器在最後一行之後崩潰。但是,如果我在這一行設置了一個斷點,則myVar1會被正確填充,但執行該行程序時會崩潰。謝謝。安卓與意圖工作

從主類

Intent intent = new Intent(getBaseContext(), myPush.class); 

intent.putExtra("myVar1", var1); 

startActivity(intent); 

和myPush類

String recVar = getIntent().getExtras().getString("myVar1"); 

編輯:已經嘗試過用Intent(this, myPush.class)Intent(currentClass.this, myPush.class)和相同的結果!

debbuger不說太多...

03-14 14:28:48.887: W/dalvikvm(2595): threadid=1: thread exiting with uncaught exception (group=0x409961f8) 
+0

嘗試將'getBaseContext()'更改爲'this'。 – 2012-03-14 14:10:45

+0

不應該是'String recVar = getIntent()。getExtras()。getString(「myVar1」);' – zapl 2012-03-14 14:27:02

回答

0

變化getBasecontext()來a.this。其中A =活動類,你 是英寸

也不要忘了把要傳輸到您的AndroidManifest.xml

+0

已經聲明清單和相同的結果。請參閱編輯 – Jaume 2012-03-14 14:33:30

+0

調試程序停止了哪一行? – sdfwer 2012-03-14 14:38:02

+0

在AndroidManifest.xml中,您是否將該活動放在另一個活動中,例如。 。如果按照這種順序放置,那將無法工作。 然後應該工作。 – sdfwer 2012-03-14 14:41:07

0

您已經使用了類

Intent intent = new Intent(getBaseContext(), myPush.class); 

改用

Intent intent = new Intent(getApplicationContext() , myPush.class); 

,或者您可以使用

Intent intent = new Intent(YOUR_CLASS.this , myPush.class); 

我認爲你的代碼有效。

+0

嘗試所有選項和結果。請參閱編輯 – Jaume 2012-03-14 14:34:04

0

嘗試:

Intent intent = new Intent(this, myPush.class); 
+0

同一問題...看編輯 – Jaume 2012-03-14 14:34:24

0

也許,如果你不喜歡這樣,只要環境的變化並沒有導致:

意向意圖=新getIntent(); String recVar = intent.getStringExtra(「myVar1」);