4

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?

Will Curran
  • 6,959
  • 15
  • 59
  • 92
  • possible duplicate of: http://stackoverflow.com/questions/3278895/how-to-check-current-running-applications-in-android – djg May 19 '11 at 19:59

3 Answers3

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.

fejd
  • 2,545
  • 1
  • 16
  • 39
keyboardP
  • 68,824
  • 13
  • 156
  • 205
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.

Community
  • 1
  • 1
CRM
  • 4,569
  • 4
  • 27
  • 33
  • 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
0

Take a look at the ActivityManager.

Haphazard
  • 10,900
  • 6
  • 43
  • 55