Skip to content

Instantly share code, notes, and snippets.

@android10
Created July 20, 2016 09:56
Show Gist options
  • Select an option

  • Save android10/6c06d488c8bd83312ab0ed947f0b5b86 to your computer and use it in GitHub Desktop.

Select an option

Save android10/6c06d488c8bd83312ab0ed947f0b5b86 to your computer and use it in GitHub Desktop.

Revisions

  1. android10 created this gist Jul 20, 2016.
    30 changes: 30 additions & 0 deletions AndroidApplication.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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
    }
    }
    }