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?
Asked
Active
Viewed 71 times
0
-
1How you are calling the C activity? From A or from B? – Pankaj Kumar Jun 13 '13 at 06:35
-
Can you provide more details on how these activities live and create from? – gunar Jun 13 '13 at 06:36
-
@Pankaj Kumar It is seperate activity I am not calling it from A or B.I just need data send by to B for updation of view purpose – Sneha Bansal Jun 13 '13 at 06:39
-
Then you have to save some where like prefs or application storage. – Pankaj Kumar Jun 13 '13 at 06:40
-
2you can use shared preferences for same.. – Mahaveer Muttha Jun 13 '13 at 06:42
-
@PankajKumar in my app A calls B number of times so do I need to save every time? – Sneha Bansal Jun 13 '13 at 06:43
-
yes if you are using prefrences, there is no problem to save everytime – Pankaj Kumar Jun 13 '13 at 06:45
4 Answers
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