开发者

detecting changes to my program's focus

开发者 https://www.devze.com 2023-03-12 21:35 出处:网络
When other programs are open in Android, how do I know when my program loses focus or gains focus? I\'ve s开发者_Go百科een the View onFocusChanged event, but I think that\'s unrelated (when i use a v

When other programs are open in Android, how do I know when my program loses focus or gains focus?

I've s开发者_Go百科een the View onFocusChanged event, but I think that's unrelated (when i use a view changer).

How can this be done?


In your Activity, you can override the life cycle methods. Specifically, onCreate, onStart, onResume, onPause, onStop and onDestroy. The most useful ones are:

  • onCreate: great for one time initialization.
  • onResume: refresh your data because your app is about to take foreground again.
  • onPause: save your data and stop anything that doesn't need to be running while your app doesn't have the foreground.

See http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle for a complete overview of these methods and your activities life cycle.

0

精彩评论

暂无评论...
验证码 换一张
取 消