我有Myactivity这是从以前的活动获取意图数据。意图数据通过活动的纺丝器发送。我想微调的意图这个数据保存到Myactvity。当我通过下一个活动的菜单选项进入Myactivity意图数据要坚持。
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
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();
}
如共享preferences [2]在你第一次ActivityA
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);
在你的第二个ActivityB
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","");
为您节省对象的目的使用共享preferences
for your object saving purpose use SharedPreferences