0

I have activity A and it calls activity B using Intent and putting some data in intent .Now I want to access data send by A in activity C.Can I do this?If Yes then how?

Sneha Bansal
  • 941
  • 1
  • 13
  • 38

4 Answers4

0

Simple Use this piece of code

String value = getIntent().getExtras().getString("keyName");


Or you can use SharedPreference in ActivityA then retrieve in ActivityC
Or You can use POJO (i.e getter & setter) to Set in in ActivityA then Get in ActivityC

e.g

    public class Example{

     private String name;
     private int age;

     public void setName(String name){
        this.name = name;
     }

     public String getName(){
        return this.name;
     }

}
Sam
  • 1,124
  • 1
  • 8
  • 12
0

Put your data in ActivityA like this

Intent intent = new Intent(this, ClassB.class);
intent.putExtra("yourKey", yourValue);
startActivity(intent);

get your values from ActivityB using this

Intent intentA = getIntent();
String yourString = intentA.getStringExtra("yourKey");

Hope this helps:)

R9J
  • 6,605
  • 4
  • 19
  • 25
0

Create the base activity for all the activities and pass the date in that activity through a method in bundle. Now you can get this data at any activity.

Muhammad Aamir Ali
  • 20,419
  • 10
  • 66
  • 57
0

You can use SharedPreferences to save values and can access it from Any ACtivity

More on Shared Preferences

Community
  • 1
  • 1
Nargis
  • 4,687
  • 1
  • 28
  • 45