Showing posts from May, 2011

Way to check whether an application is running in Android

Today I came across one interesting thing in Android and I would like to share with you all. In this post I am going to explain the power of the class RunningAppProcessInfo. Through this class we can check whether the application is running, if it is running what is the importance of it, like whether it is in foreground, background, visible etc.

The code snippet is,

ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> runningProcInfo = activityManager .getRunningAppProcesses(); for(int i = 0; i < runningProcInfo.size(); i++){ if(runningProcInfo.get(i).processName.equals("")) { Log.i(TAG, "XXXX is running"); } }

To check the omportance of the process, that is whether it is foreground or in background etc, we can check through the field lru.

for(int i = 0; i < runningProcInfo.size(); i++){ if(runningProcInfo.get(i).processName.equal…

Capture Screen in Android

Capturing screen is a very useful thing in lot of projects. We can use it for thumbnail, in some cases can use it for Animations etc. This post mainly shows the power of setDrawingCacheEnabled() method in Android's View class. Most common use is take the screen shot and use it as a thumbnail. Take a view from the layout xml file and use the code snippet,

TextView tv = (TextView) findViewById(;
View img = (View) findViewById(;
img = tv.getRootView();
Bitmap bmp = img.getDrawingCache();
ImageView image = (ImageView) findViewById(;