3

I have succeeded in launching the default home launcher through the following code while working with the emulator:

Intent de_intent=new Intent();
de_intent.setClassName("com.android.launcher","com.android.launcher2.Launcher");
startActivity(de_intent);

But when I am executing this code in the real device, it is showing following exception:

Unable to find explicit activity class {com.android.launcher/com.android.launcher2.Launcher} have you declared this in AndroidManifest.xml

Can anybody help me to solve this issue?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ganesh
  • 35
  • 2
  • 5

3 Answers3

5

Do you have a Samsung device? They replaced the default Android launcher with their TouchWiz Home launcher. The following code worked for me using the setClassName() method:

Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setClassName("com.sec.android.app.launcher", "com.android.launcher2.Launcher");
        startActivity(intent);
Martin
  • 326
  • 4
  • 9
2

If you want to return to HOME, you can use:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
auselen
  • 27,577
  • 7
  • 73
  • 114
2

try following:

 Intent startMain = new Intent(Intent.ACTION_MAIN);
        startMain.addCategory(Intent.CATEGORY_HOME);
        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(startMain);
Praful Bhatnagar
  • 7,425
  • 2
  • 36
  • 44