How to restart the onCreate function

I have an application, and there are certain conditions when I want my activity to be recreated, or I need the onCreate function onCreate that I can perform various functions again. Just like when the device orientation changes and the oncreate function is called or the activity is recreated, in the same way I want my application to be restarted. I am currently using this.onCreate(null) , but I think this is not the best way.
Please give some suggestions. thanks a lot

+6
source share
1 answer

How about creating a method outside of your onCreate () that performs all the actions, and in the onCreate method, it calls this to load the Activity. If you need to update your activity, just call this new method. For instance:

 @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(); } }; 
+19
source

Source: https://habr.com/ru/post/895606/


All Articles