lundi 18 mai 2015

Android App Getting Killed on Intent Launch

I have an app which is kept hidden from the launcher. Now I want to open the app from the dialer. So I have a BroadcastReceiver where I am handling things.

1) First I show the app,

ComponentName componentName = new ComponentName(context,
                SplashActivity.class);
        context.getPackageManager().setComponentEnabledSetting(
                componentName,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);

2) Then launch an Intent,

Intent launcher = new Intent(context, SplashActivity.class);
                    launcher.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    context.startActivity(launcher);

3) Then I am hiding the app again,

ComponentName componentName2 = new ComponentName(context,
                SplashActivity.class);
        context.getPackageManager().setComponentEnabledSetting(
                componentName2,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);

The Problem

The Intent launch is successful but the app is getting killed after a few seconds. But the problem doesn't occur if I launch any other activity other than the SplashActivity. What is the problem and how can it be solved?

Aucun commentaire:

Enregistrer un commentaire