-
-
Save jesselima/c6b55fa6fe881739d37a6f0f10a50e84 to your computer and use it in GitHub Desktop.
Sample usage of the "android.app.Application.ActivityLifecycleCallbacks" class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity { | |
private final MyActivityLifecycleCallbacks mCallbacks = new MyActivityLifecycleCallbacks(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
// Always register before calling into the super class. | |
getApplication().registerActivityLifecycleCallbacks(mCallbacks); | |
super.onCreate(savedInstanceState); | |
} | |
@Override | |
protected void onDestroy() { | |
super.onDestroy(); | |
// Always unregister after calling into the super class. | |
getApplication().unregisterActivityLifecycleCallbacks(mCallbacks); | |
} | |
public static class MyActivityLifecycleCallbacks implements ActivityLifecycleCallbacks { | |
@Override | |
public void onActivityCreated(Activity activity, Bundle savedInstanceState) { | |
Log.i(activity.getClass().getSimpleName(), "onCreate(Bundle)"); | |
} | |
@Override | |
public void onActivityStarted(Activity activity) { | |
Log.i(activity.getClass().getSimpleName(), "onStart()"); | |
} | |
@Override | |
public void onActivityResumed(Activity activity) { | |
Log.i(activity.getClass().getSimpleName(), "onResume()"); | |
} | |
@Override | |
public void onActivityPaused(Activity activity) { | |
Log.i(activity.getClass().getSimpleName(), "onPause()"); | |
} | |
@Override | |
public void onActivitySaveInstanceState(Activity activity, Bundle outState) { | |
Log.i(activity.getClass().getSimpleName(), "onSaveInstanceState(Bundle)"); | |
} | |
@Override | |
public void onActivityStopped(Activity activity) { | |
Log.i(activity.getClass().getSimpleName(), "onStop()"); | |
} | |
@Override | |
public void onActivityDestroyed(Activity activity) { | |
Log.i(activity.getClass().getSimpleName(), "onDestroy()"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment