首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重载onResume()

重载onResume()
EN

Stack Overflow用户
提问于 2014-02-14 06:15:45
回答 3查看 192关注 0票数 0

如何重载onResume()才能正常工作?我想从activity返回到MainActivity,在那里我想拥有与应用启动后相同的状态。我想使用recreate(),但它发生了循环或类似的情况。

我的代码:

代码语言:javascript
复制
@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    recreate();
}
EN

回答 3

Stack Overflow用户

发布于 2014-02-14 07:27:44

实现onSaveInstanceState(Bundle save)onRestoreInstanceState(Bundle restore)来保存和恢复状态。请参阅the documentation on this.

票数 1
EN

Stack Overflow用户

发布于 2014-02-14 07:21:43

我猜,当您按下back按钮时,您想要刷新上一个活动。

这非常简单,您只需将您的方法放在onResume()中,它就可以完成此任务。

票数 0
EN

Stack Overflow用户

发布于 2014-02-14 07:42:59

好的,试试这个,它对我很有效。

代码语言:javascript
复制
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. 
   }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21766703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档