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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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