Skip to content

Instantly share code, notes, and snippets.

@memfis19
Forked from android10/AndroidApplication.java
Created October 31, 2016 10:48
Show Gist options
  • Save memfis19/e4c6c21781be069e04df2bf1b7f84b86 to your computer and use it in GitHub Desktop.
Save memfis19/e4c6c21781be069e04df2bf1b7f84b86 to your computer and use it in GitHub Desktop.
Android: how to know if your app is completely hidden
public class AndroidApplication extends MultiDexApplication {
public static final String TAG = AndroidApplication.class.getSimpleName();
@Override
public void onCreate() {
super.onCreate();
registerComponentCallbacks(new ComponentCallback());
}
private class ComponentCallback implements ComponentCallbacks2 {
@Override
public void onTrimMemory(int level) {
if(level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
Log.d(TAG, "Application not visible anymore");
} else if (level == ComponentCallbacks2.TRIM_MEMORY_COMPLETE) {
Log.d(TAG, "Application is going to be killed");
}
}
@Override
public void onLowMemory() {
onTrimMemory(TRIM_MEMORY_COMPLETE);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
//no op
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment