2014-03-03 27 views
-1
protected void onMessage(Context context, Intent intent) { 


     String msg = intent.getStringExtra("payload"); 
     String newspushid1= intent.getStringExtra("payload1"); 
     gc.setnews_pushid(newspushid1); 
     mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     BackgroundAlert bg = new BackgroundAlert(mNotificationManager, msg); 
     bg.onReceive(getApplicationContext(), intent); 
    } 

在這裏我得到了msg和Push id的值(分別爲helloworld和101)我想在另一個活動中獲得這個值。在android中無法獲取Push值

if (gdata.getPush_message() != null) { 

      String push_id_value = gdata.getnews_pushid(); 

      Log.e("CATID", "ID-->" + push_id_value); 
} 

我已經使用這個代碼用於獲取價值。從GCMIntentService類,但我得到相同的值push_id_value,getPush_message其中世界您好我無法得到另一個動作和值101,請檢查我的代碼告訴另外活動我解決方案。

+0

這裏是什麼'gdata'? –

+0

它是seter和geter類的對象 – user3292460

+0

哦,那麼罰款那麼你設置的價值? –

回答

1

創建Constant類,如:

public class Constant {  
public static String PAYLOAD = ""; 
public static String PAYLOAD_1 = ""; 
} 

現在,你可以設置像

Constant.PAYLOAD = intent.getStringExtra("payload"); 
Constant.PAYLOAD_1= intent.getStringExtra("payload1"); 

Activity1這個值現在,在Activity2得到這個值,如:

String push_id_value = Constant.PAYLOAD; 
String push_id_value1 = Constant.PAYLOAD_1; 

和/或爲首選ence轉到我的回答:Android. How to save user name and password after the app is closed?

+0

其工作正常 – user3292460

+0

@ user3292460喲歡迎! –

+0

我可以有你的電子郵件ID PLZ .. – user3292460

1

在你當前活動,

Intent i = new Intent(getApplicationContext(), NewActivity.class); 
i.putExtra("new_variable_name","value"); 

然後在新的活動,檢索這些值:

Bundle extras = getIntent().getExtras(); 
if (extras != null) { 
    String value = extras.getString("new_variable_name"); 
} 

使用此技術從一個活動值傳遞給另一個。

+0

獲取所有值看到我是從服務器Pusing值 – user3292460

+0

@AB你'正在路上。 +1在這裏問題一些其他地方。 –