KomalG
KomalG

Reputation: 788

How to finish my custom launcher Programmatically in android

I am developing an application my requirement is to finish my custom launcher and switch to default launcher. How can I achieve that?

Upvotes: 0

Views: 862

Answers (1)

Rathan Kumar
Rathan Kumar

Reputation: 2577

follow the following steps:

  1. By using Package Manager get the intents which is having launcher and category home. By using queryIntents method.

  2. Use the 0th indexed intent and get the class name and package name. store some where else like sharedPreferences.

  3. whenever you want to launch the default launcher just create intent with class name and packager name.

  4. Then start that activity when it is required.

Following code may help you:

        PackageManager packageManager = getPackageManager();
        Intent i = new Intent();
        i.addCategory(Intent.CATEGORY_HOME);
        i.setAction(Intent.ACTION_MAIN);
        List<ResolveInfo> queryIntentActivities = packageManager
                .queryIntentActivities(i, 0);

        ResolveInfo resolveInfo = queryIntentActivities.get(0);
        String packageName = resolveInfo.resolvePackageName;
        String className = resolveInfo.activityInfo.targetActivity;

Upvotes: 0

Related Questions