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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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();
}
};