Friday, April 20, 2012

how to Check application is running or not in through background service in Android ?

// get a list of running processes and iterate through them
            ActivityManager am = (ActivityManager) this

            // get the info from the currently running task
            List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);

            Log.d("current task :", "CURRENT Activity ::"
                    + taskInfo.get(0).topActivity.getClass().getSimpleName());

            ComponentName componentInfo = taskInfo.get(0).topActivity;
            Intent i;

            //if  app is running
            if(componentInfo.getPackageName().equalsIgnoreCase(*Package Name*))

                //do the implementation for if your app is running


No comments:

Post a Comment