Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use onWindowFocusChanged() method?

Tags:

android

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 it. Please help in one example i.e. when the activity changes, it should show a toast said "Activity changed".

like image 211
abuybuy Avatar asked Oct 28 '11 01:10

abuybuy


1 Answers

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();  } 
like image 100
Reno Avatar answered Sep 23 '22 10:09

Reno