I created an app to load all installed applications. It's working fine now. But with some phones/tablets that have a lot of applications, my app crashes because of Out Of Memory. Below is the source code to get application info
String appName = p.applicationInfo.loadLabel(packageManager).toString();
String packageName = p.packageName;
String appFile = a.sourceDir;
long lastUpdated = new File(appFile).lastModified();
Drawable icon = a.loadIcon(packageManager);
AppSize appSize = calculateSize(p.applicationInfo.sourceDir);
App application = new App(appName, packageName, lastUpdated, appSize.getSize(), appSize.getLongSize(), icon, false);
Is there any way to optimize above code to avoid out of memory? Thank you.
Please have look at this link: Displaying bitmaps efficiently.
Also at this open source library project: Universal Image loader.
when your application needs to display lots of bitmaps, it exceeds allocated memory of application. Also, when they are displayed in grid,list or view pager more memory is consumed while creating each views. hence you need to cache in those images in memory or disc and display them efficiently using the techniques described in those links.
Take a look at this: Get installed Applications with Name, Package Name, Version and Icon
Acceptable URI's Examples for UIL: