-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);
    }

In this i am Getting value of msg and Push id (helloworld and 101 respectively) i want get this value in another activity .

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

            String push_id_value = gdata.getnews_pushid();

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

I have apply this code for getting value .from GCMIntentService class but i am getting same value push_id_value ,getPush_message in another activity which is hello world i am unable to get value 101 in another activity please check my code tell me solution .

2 Answers2

1

In your current Activity,

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

Then in the new Activity, retrieve those values:

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

Use this technique to pass values from one Activity to another.

Adhikari Bishwash
  • 2,770
  • 28
  • 32
1

Create a Constant Class like :

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

Now, you can set this value in Activity1 like

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

Now, get this value in Activity2 like:

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

And/or for Preference go to my this answer:Android. How to save user name and password after the app is closed?

Community
  • 1
  • 1
M D
  • 47,665
  • 9
  • 93
  • 114