Hi Narasimha,
I believe you could do something like this:
I wrote the the below snippet as a Hack to kill the activity that is currently running (except launcher) .. ;)
--
+ ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
+ // The first in the list of RunningTasks is the foreground task.
+ RunningTaskInfo foregroundTaskInfo = am.getRunningTasks(1).get(0);
+ String foregroundTaskPackageName = foregroundTaskInfo.topActivity.getPackageName();
+ Log.i(TAG, "Printing the Top FG activity: " + foregroundTaskPackageName);
+
+ PackageManager pm = mContext.getPackageManager();
+ PackageInfo foregroundAppPackageInfo = pm.getPackageInfo(foregroundTaskPackageName, 0);
+ String foregroundTaskAppName = foregroundAppPackageInfo.applicationInfo.loadLabel(pm).toString();
+ Log.i(TAG, "Printing the Top FG App Label: " + foregroundTaskAppName);
+
+ List<ActivityManager.RunningAppProcessInfo> listOfProcesses = am.getRunningAppProcesses();
+ for (int i = 0; i < listOfProcesses.size(); i++) {
+ ActivityManager.RunningAppProcessInfo proc = listOfProcesses.get(i);
+ //don't kill the launcher..It will keep restarting(launcher is the home screen App)
+ if (proc.processName.equalsIgnoreCase("com.android.launcher"))
+ continue;
+ if(proc.processName.equalsIgnoreCase(foregroundTaskPackageName)) {
+ curFGTaskPid = proc.pid;
+ Log.i(TAG, "Printing the Top FG activity's PID: " + curFGTaskPid);
+ break;
+ }
+ }
+
+ android.os.Process.killProcess(curFGTaskPid);
Thanks,
Durga