Android 如何在使用此方法销毁活动时保存状态
} 好的,我想知道如何保存这个活动的状态。这只是我代码中的一个小片段,向大家展示一个示例。因此,我希望保存状态,以便当活动被销毁时,用户将返回他们停止的位置。Android 如何在使用此方法销毁活动时保存状态,android,Android,} 好的,我想知道如何保存这个活动的状态。这只是我代码中的一个小片段,向大家展示一个示例。因此,我希望保存状态,以便当活动被销毁时,用户将返回他们停止的位置。 第二件事,我想在每次按钮点击之间显示一个快速的5秒进度对话框微调器 第二件事 这应该起作用: public class Talk extends Activity { private ProgressDialog progDialog; int typeBar; TextView text1; EditText edit; But
第二件事,我想在每次按钮点击之间显示一个快速的5秒进度对话框微调器 第二件事 这应该起作用:
public class Talk extends Activity {
private ProgressDialog progDialog;
int typeBar;
TextView text1;
EditText edit;
Button respond;
private String name;
private String textAtView;
private String savedName;
public void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.dorothydialog);
text1 = (TextView)findViewById(R.id.dialog);
edit = (EditText)findViewById(R.id.repsond);
respond = (Button)findViewById(R.id.button01);
respond.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text1.setText("Welcome! Enter your name!");
respond.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
name = edit.getText().toString();
text1.setText("Cool! your name is "+name);
}
});
}
});
}
现在唯一的问题是,我希望runDialog()在我上面的方法中文本显示在textView上之前显示;在textView.setText()之前;我这样做了,但它仍然一起做。解释应用程序/活动生命周期及其回调方法,并解释保存持久状态。第二件事,你真的想在每次按钮点击之间有一个5秒的进度对话框微调器吗?或者您更愿意有5秒钟的时间暂停用户输入?
public class TestActivity extends Activity implements Runnable, OnClickListener {
private TextView tv;
private ProgressDialog pd;
private Button btn;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
tv = (TextView) this.findViewById(R.id.tv);
btn = (Button)findViewById(R.id.btn);
tv.setText("initial text");
btn.setOnClickListener(this);
}
public void onClick(View v) {
pd = ProgressDialog.show(TestActivity.this, "Please wait...", "Details here", true, false);
Thread thread = new Thread(TestActivity.this);
thread.start();
}
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.sendEmptyMessage(0);
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
pd.dismiss();
tv.setText("text after 5 sec passed");
}
};
}