我有Myactivity,它从前一个活动获取意图数据。意图数据通过活动的微调器发送。我想将微调器的这个意图数据保存到Myactvity。当我进入下一个活动的Myactivity through菜单选项时,意图数据应该保持不变。
答案 0 :(得分:3)
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] 在你的第一个活动A
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