0

I my app i have two class are passing a intent value to another one class ,but in a Received class ,how to set the two intent values to one same variable

manes, first one Activity pass the intent to that class , and after another Activity pass the value to same class and in Received class set the intent value to same variable

Anil M H
  • 3,332
  • 5
  • 34
  • 51

1 Answers1

0

You can use SharedPreference to maintain Data. U can save your value from following method in Both Activities

private void SavePreferences(String key, String value) {
        SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key, value);
        editor.commit();
    }

U can retrive the value in any Activity.

private void showPreferences(String key){
        SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
        String savedPref = sharedPreferences.getString(key, "");
        myTextView.setText(savedPref);
       }

Still If u want to Use Intent.U can use it. Add Two of your Sender Activity

Pass the values:

Intent intent = new Intent(getBaseContext(), SecondActivity.class);
intent.putExtra("EXTRA_item", item);
startActivity(intent);

here, value of "item" be varied as u pass it. You can retrieve it in Receiver Activity:

Get the Values in SecondActivity :

Intent intent = getIntent();
String string = intent.getStringExtra("EXTRA_item");

Here, string will get last Sender Activity Intent's "item" value.

Bhoomika Brahmbhatt
  • 7,404
  • 3
  • 29
  • 44