我有Myactivity这是从以前的活动获得意图数据。 这样做的目的数据通过活动的微调发送。 我要微调的这种意图数据保存到Myactvity。 当我通过下一个活动的菜单选项进入Myactivity意图数据应该坚持。
Answer 1:
在你第一次活动1
Intent myintent= new Intent(FirstActivity.this,SecondActivity.class);
myintent.putExtra("Name", "your String");
startActivity(myintent);
在第二活性2
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();
}
像SharedPreferences [2]在你第一次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);
在你的第二个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","");
为您节省对象的用途使用SharedPreferences
文章来源: how to save intent data passed from 1st activity to 2nd activity