Execute a method after an activity is visible to user

前端 未结 5 850
无人及你
无人及你 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 19:06

    there is no real callback, which is called, exactly at that time the Activity is Visible. But as you can see in the attached picture, the method onResume() is just called when Activity should be visible.

    Also have a look at the Activity lifecycle and the documentation HERE

    So your method should be called like this:

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

提交回复
热议问题