Is there a way to get a common drum device? I need it to optimize

I have lrucache that can contain static data, so even if my application closes when the user returns, he can find the data faster.

However, it takes about 10-15 MB of memory, so I would like to create an if branch like this

if(deviceOverallRAM > treshold) preserve static memory on app exit else clear static memory on app exit 

So, can I get the device, possibly through some kind of hidden api? And what would be good value for this?

+6
source share
1 answer

To execute this pre-API 16, you must read the proc / meminfo file of the Android kernel:

  public long getTotalMemory() { String str1 = "/proc/meminfo"; String str2; String[] arrayOfString; long initial_memory = 0; try { FileReader localFileReader = new FileReader(str1); BufferedReader localBufferedReader = new BufferedReader( localFileReader, 8192); str2 = localBufferedReader.readLine();//meminfo arrayOfString = str2.split("\\s+"); for (String num : arrayOfString) { Log.i(str2, num + "\t"); } //total Memory initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024; localBufferedReader.close(); return initial_memory; } catch (IOException e) { return -1; } } 

Source: This Question

However, in API 16 onwards, you can use the following code to retrieve full memory:

 ActivityManager actManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); MemoryInfo memInfo = new ActivityManager.MemoryInfo(); actManager.getMemoryInfo(memInfo); long totalMemory = memInfo.totalMem; 
+20
source

Source: https://habr.com/ru/post/926044/


All Articles