How to restart the onCreate function

后端 未结 1 1496
天涯浪人
天涯浪人 2020-12-17 01:17

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

相关标签:
1条回答
  • 2020-12-17 01:25

    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();
        }
    };
    
    0 讨论(0)
提交回复
热议问题