如何重新启动onCreate函数 [英] How to restart the onCreate function

查看:385
本文介绍了如何重新启动onCreate函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,并且在某些情况下我想重新创建我的活动或需要调用onCreate函数,以便可以再次执行不同的功能.就像当设备的方向改变并且调用oncreate函数或重新创建活动时一样,我也希望我的应用程序重新启动.目前,我正在使用this.onCreate(null),但是我认为这不是最好的方法. 请提供一些建议.
非常感谢

I have an application and there are certain conditions when I want my activity to be recreated or the onCreate function is needed to be called so that different functions can be performed again. Just like when the orientation of the device changes and the oncreate function is recalled or the activity is recreated, in the same way, I want my application to be restarted. Currently I am using this.onCreate(null) but I think this is not the best way..
Please give some suggestions.
Thanks alot

推荐答案

如何在onCreate()外部创建一个可以完成所有Activity工作的方法,并在onCreate方法中调用该方法来加载Activity.如果您需要刷新活动",只需调用该新方法即可.例如:

How about creating a method outside of your onCreate() that does all of the Activities work, and in your onCreate method, it calls that to load the Activity. If you need to refresh your Activity, just call that new method. For example:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    loadActivity();
}

private void loadActivity() {
    // Do all of your work here
}

private OnClickListener ReloadActivity = new OnClickListener() {
    public void onClick(View v) {
        loadActivity();
    }
};

这篇关于如何重新启动onCreate函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆