这篇文档教你在activity状态改变时如何保存和恢复数据!
上代码PersistentState.java:
public class PersistentState extends Activity
{
/**
* Initialization of the Activity after it is first created. Here we use
* {@link android.app.Activity#setContentView setContentView()} to set up
* the Activity's content, and retrieve the EditText widget whose state we
* will persistent.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// Be sure to call the super class.
super.onCreate(savedInstanceState);
// See assets/res/any/layout/save_restore_state.xml for this
// view layout definition, which is being set here as
// the content of our screen.
setContentView(R.layout.save_restore_state);
// Set message to be appropriate for this screen.
((TextView)findViewById(R.id.msg)).setText(R.string.persistent_msg);
// Retriev