如何重载onResume()才能正常工作?我想从activity返回到MainActivity,在那里我想拥有与应用启动后相同的状态。我想使用recreate(),但它发生了循环或类似的情况。
我的代码:
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
recreate();
}发布于 2014-02-14 07:27:44
实现onSaveInstanceState(Bundle save)和onRestoreInstanceState(Bundle restore)来保存和恢复状态。请参阅the documentation on this.
发布于 2014-02-14 07:21:43
我猜,当您按下back按钮时,您想要刷新上一个活动。
这非常简单,您只需将您的方法放在onResume()中,它就可以完成此任务。
发布于 2014-02-14 07:42:59
好的,试试这个,它对我很有效。
public class main extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
//add any buttons or anything you have here.
doMainWork(); \\lets just say you have this method, which contains the main code of the layout.
}
protected void onResume(){
super.onResume();
doMainWork();
}
public void doMainWork(){
\\Put all your working code here. And this should work it out man.
}https://stackoverflow.com/questions/21766703
复制相似问题