希望您了解Android中SharedPreferences的概念。使用它,你可以满足这个要求。它是一个全球性的地方,你可以从你的应用程序的任何地方设置它的价值,并在任何需要的地方使用同一个应用程序!
在活动1,
SharedPreference s_pref=PreferenceManager.getDefaultSharedPreferences(context);
Editor edit=s_pref.edit();
button1.setOnClick....()
{
... onClick()
{
edit.putString("textview_text","some text");
edit.commit();
/* you can start activity from here
Intent intent = new Intent(Activity1.this, Activity2.class);
startActivity(intent);
*/
//even if you don't start activity from here,text changed would be reflected in textView1 when activity2 is loded
}
}
button2.setOnClick....()
{
... onClick()
{
edit.putString("textview_text","some other text");
edit.commit();
/* you can start activity from here
Intent intent = new Intent(Activity1.this, Activity2.class);
startActivity(intent);
*/
//even if you don't start activity from here,text changed would be reflected in textView1 when activity2 is loded
}
}
在活性2
,
...
SharedPreference s_pref=PreferenceManager.getDefaultSharedPreferences(context);
Editor edit=s_pref.edit();
String text=s_pref.getString("textview_text", "default text");
textView1.setText(text);
...
请清除掉,是你在activity2中的唯一textview和两个按钮在activity1.is中是正确的? – Hiral 2012-02-09 06:20:06