Assume Applications Foo an Eggs are on the same Android device. It's possible for either application to get a list of all applications on the device. Is it possible for one application to know if another application has run and for how long?
Asked
Active
Viewed 6,773 times
4
-
possible duplicate of: http://stackoverflow.com/questions/3278895/how-to-check-current-running-applications-in-android – djg May 19 '11 at 19:59
3 Answers
4
You can get a list of installed applications by using the PackageManager. Code from here:
public class AppList extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
Log.w("Installed Applications", rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}
}
}
To see the currently running apps, you can use the ActivityManager.
1
This post explains how you can achieve that functionality in a generic way.
This post and this one have snippets of an Activity that lists the running applications, using ActivityManager
's getRunningAppProcesses()
.
This post explains how to get a list of all installed applications and then to choose one to run.
-
It should be added that you'll need to add a permission to your manifest to use getRunningTasks() or getRecentTasks(). android.permission.GET_TASKS to be exact. – Maximus May 19 '11 at 20:21