How to Detect Lowmemory in android?

前端 未结 7 1651
-上瘾入骨i
-上瘾入骨i 2021-02-13 14:34

My application has a lot of images and sometimes it crashes due to low memory. I wrote this function that I found on the developer site.

public void onLowM         


        
7条回答
  •  感动是毒
    2021-02-13 15:29

    Here is an example of how I'm using onLowMemory, implemented in MyApplication To clean things up, I do flush memory caches (which is used mainly for images), and google tracker;

    @Override
        public void onLowMemory() {
            super.onLowMemory();
            Log.w(TAG, "onLowMemory() -> clearImageCacheFu!!!");
            clearImageCacheFu();
    
            dispatchGoogleTracker();
            stopGoogleTracker();
        }
    

    This may give you an idea to adapt as per your need. hope this helps.

提交回复
热议问题