Execute a method after an activity is visible to user

前端 未结 5 859
无人及你
无人及你 2021-01-31 18:04

I have an activity contains too many UI controls. I want to execute a method after make the activity visible.

An example i tried:

publi         


        
5条回答
  •  臣服心动
    2021-01-31 18:54

    Move the code on to onResume.

    System calls this method every time your activity comes into the foreground, including when it's created for the first time. Read details for Pausing and Resuming an Activity

    @Override
    protected void onResume() {
        super.onResume();
    
        MyMethod();
    }
    

    Read more at Android activity life cycle - what are all these methods for?

提交回复
热议问题