Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Activity Lifecycle Logger, not support onActivityResult()
//call if(BuildConfig.DEBUG) registerActivityLifecycleCallbacks(new ActivityLifecycleLogger()) in your own Application class.
public class ActivityLifecycleLogger implements Application.ActivityLifecycleCallbacks {
private static final String TAG = "LifeCycleLogger";
private static final Class[] LOG_CYCLE_ACTIVITIES = new Class[] {
//add activities you want to log here
MainActivity.class
};
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if (inGroup(activity)) Log.d(TAG, activity.getLocalClassName() + " onCreate");
}
@Override
public void onActivityStarted(Activity activity) {
if (inGroup(activity)) Log.d(TAG, activity.getLocalClassName() + " onStart");
}
@Override
public void onActivityResumed(Activity activity) {
if (inGroup(activity)) Log.d(TAG, activity.getLocalClassName() + " onResume");
}
@Override
public void onActivityPaused(Activity activity) {
if (inGroup(activity)) Log.d(TAG, activity.getLocalClassName() + " onPause");
}
@Override
public void onActivityStopped(Activity activity) {
if (inGroup(activity)) Log.d(TAG, activity.getLocalClassName() + " onStop");
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
if (inGroup(activity)) Log.d(TAG, activity.getLocalClassName() + " onSaveInstanceState");
}
@Override
public void onActivityDestroyed(Activity activity) {
if (inGroup(activity)) Log.d(TAG, activity.getLocalClassName() + " onDestroy");
}
private static boolean inGroup(Activity activity) {
for (Class clazz : LOG_CYCLE_ACTIVITIES) {
if (clazz.isInstance(activity)) return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.