I have Myactivity which is getting the intent data from the former activity. The intent data is sent through a spinner of the activity. I want to save this intent data of the spinner to the Myactvity. the intent data should persist when i enter the Myactivity through menu option of next activity.
Asked
Active
Viewed 3,783 times
1 Answers
3
in your First Activity1
Intent myintent= new Intent(FirstActivity.this,SecondActivity.class);
myintent.putExtra("Name", "your String");
startActivity(myintent);
in Second Activity2
Intent myintent = getIntent();
if(null!=myintent.getExtras()){
String Name= myintent.getExtras().getString("Name");
Toast.makeText(getApplicationContext(),""+Name,12).show();
}else{
Toast.makeText(getApplicationContext(),"No Recor Here..",12).show();
}
like SharedPreferences[2] in your First ActivityA
Intent myintent= new Intent(FirstActivity.this,SecondActivity.class);
SharedPreferences spref = this.getSharedPreferences("mynotifyid", MODE_WORLD_WRITEABLE);
SharedPreferences.Editor spreedit = spref.edit();
spreedit.putString("Name1", str1.toString());
spreedit.putString("Name2", str2.toString());
spreedit.putString("Name3", str3.toString());
spreedit.putString("Name4", str4.toString());
spreedit.commit();
startActivity(myintent);
in your Second ActivityB
SharedPreferences spref = context.getSharedPreferences("mynotifyid", Context.MODE_WORLD_WRITEABLE);
String str1 = spref.getString("Name1","");
String str2 = spref.getString("Name2","");
String str3 = spref.getString("Name3","");
String str4 = spref.getString("Name4","");
for your object saving purpose use SharedPreferences

Cody
- 484
- 6
- 20

Ankitkumar Makwana
- 3,475
- 3
- 19
- 45
-
Can the code make use of sharedpreference? Instead of toast how to make use of sharedpreference for persisting the intent data? – user1611632 Sep 14 '12 at 14:52