Remove Activity as Default Launcher

Posted by sixeightzero on Stack Overflow See other posts from Stack Overflow or by sixeightzero
Published on 2012-09-26T03:36:12Z Indexed on 2012/09/26 3:37 UTC
Read the original article Hit count: 382

I set my activity as a default launcher to intercept home button clicks like so:

<activity
    android:name=".ExampleActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.HOME" />        
        <category android:name="android.intent.category.DEFAULT" />               
    </intent-filter>
</activity>

When my activity, ExampleActivity is launched, if i click the home key, I get prompted to choose. If I select make this my default and chose my activity, I am stuck In my activity as desired.

The problem is, when I leave the activity, I try to remove my activity from the default launcher, but am unsuccessful.

I have tried:

ComponentName componentName = new ComponentName( 
                    "com.example.exampleactivity", 
                    "com.example.exampleactivity.class");

pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);

And:

PackageManager pm = getActivity().getPackageManager();
             ComponentName name = new ComponentName(this, "com.example.exampleactivity.class");
             pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);

But my designation for the home is never removed.

Does anyone have a working way to fix the above?

I only wan't the home button to be default for a specific activity, not my entire application. When I leave the activity, it should be removed and restored to default.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-intent