25

I'm trying to make a custom launcher for android, and I'm trying to figure out how to launch a different application form mine. I figured the way to do it was intents, and I've found a post on it here:

Open another application from your own (intent)

I don't really understand the answer though! Can someone give me a concise snippet or series of steps to go from a single ResolveInfo to launching the app represented by that ResolveInfo?

Community
  • 1
  • 1
Pete.Mertz
  • 1,232
  • 1
  • 16
  • 34

2 Answers2

48

Given a ResolveInfo named launchable:

ActivityInfo activity=launchable.activityInfo;
ComponentName name=new ComponentName(activity.applicationInfo.packageName,
                                     activity.name);
Intent i=new Intent(Intent.ACTION_MAIN);

i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
i.setComponent(name);

startActivity(i);

(from https://github.com/commonsguy/cw-omnibus/tree/master/Introspection/Launchalot)

CommonsWare
  • 910,778
  • 176
  • 2,215
  • 2,253
21

Create an new Intent by this way.

    Intent intent = new Intent();
    intent.setClassName(resolveInfo.activityInfo.applicationInfo.packageName,
            resolveInfo.activityInfo.name);
    startActivity(intent);
Daniel De León
  • 11,681
  • 5
  • 76
  • 66
  • 1
    could the 2nd line be shorter? intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name); – Alpha Huang Jun 09 '16 at 18:20