Last active
August 29, 2015 14:05
-
-
Save fmt-Println-MKO/e7f305251fccd31ca732 to your computer and use it in GitHub Desktop.
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
package com.github.fmtprintlnmko.util; | |
import android.app.Activity; | |
import android.app.Application.ActivityLifecycleCallbacks; | |
import android.os.Bundle; | |
public static final class MyActivityLifecycleCallbacks implements ActivityLifecycleCallbacks { | |
private AtomicInteger count = new AtomicInteger(0) ; | |
public void onActivityCreated(Activity activity, Bundle bundle) { | |
} | |
public void onActivityDestroyed(Activity activity) { | |
} | |
public void onActivityPaused(Activity activity) { | |
count.incrementAndGet(); | |
} | |
public void onActivityResumed(Activity activity) { | |
count.decrementAndGet(); | |
} | |
public void onActivitySaveInstanceState(Activity activity, Bundle outState) { | |
} | |
public void onActivityStarted(Activity activity) { | |
count.decrementAndGet(); | |
} | |
public void onActivityStopped(Activity activity) { | |
count.incrementAndGet(); | |
} | |
public boolean isAppResumed() { | |
return count.get() == 2; | |
} | |
} |
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
package com.github.fmtprintlnmko.util; | |
import android.content.res.Configuration; | |
public class MyApplication extends Application { | |
@Override | |
public void onCreate (){ | |
super.onCreate(); | |
registerActivityLifecycleCallbacks(new MyActivityLifecycleCallbacks()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment