How to use onWindowFocusChanged() method?

前端 未结 3 358
温柔的废话
温柔的废话 2020-12-14 07:22

I am confused in how to trigger an event when the activity is changed. One thing that I know is using onWindowFocusChanged() method but I don\'t know how to use

3条回答
  •  鱼传尺愫
    2020-12-14 08:06

    The following method gets called when window's focus changes. For instance, if the window gains/losses focus, it will be triggered. In case, the window gains focus, hasFocus is true and false otherwise.

     public void onWindowFocusChanged(boolean hasFocus) {         
         super.onWindowFocusChanged(hasFocus);
         if(hasFocus) 
             Toast.makeText(context, text, duration).show();
     }
    

提交回复
热议问题