Tuesday, September 23, 2014

Android - How to print tasks activity stack in terminal (backstack)

Use adb shell (in a terminal, go in <android-sdk-folder>/platform-tools).

To print a bunch of useful information:
./adb shell dumpsys activity -package 


To print only activities:
./adb shell dumpsys activity -package <your.package.name> | grep 'ACTIVITY'


To print only activities and their fragments:
./adb shell dumpsys activity -package <your.package.name> | grep -E 'ACTIVITY|Active Fragments|#[0-9]:|Added Fragments|Back Stack'

Android - Calculate optimized cache size

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

// This is how hard of a memory limit we should impose on ourselves to let system work best
// Typical values are 48MB on Nexus S, 64MB on Galaxy Nexus
int memoryClassBytes = am.getMemoryClass() * 1024 * 1024;

// Let's take only 10% of it for caching
int optimizedCacheSize = memoryClassBytes / 10;