Q:

detecting changes to my program's focus

When other programs are open in Android, how do I know when my program loses focus or gains focus?
I've seen the View onFocusChanged event, but I think that's unrelated (when i use a view changer).
How can this be done?

A:

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.

