Android reinstall failed after startup activity was disabled

I want to remove my application from the list of applications and the list of recent applications. So I tried to disable main / launch activity with the following code:

ComponentName componentToDisable = new ComponentName(context, MainActivity.class);
context.getPackageManager().setComponentEnabledSetting(componentToDisable,
           PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

It does the job. But now I'm trying to reinstall the application, and it does not say that "the activity of the MainActivity class does not exist." If I uninstall the application, the installation will work again. How can I deal with this problem? Thanks so much for your time and help.

+5
source share
1 answer

, , . , package_add/remove onReceive .

public void onReceive(Context context, Intent intent) {
    Log.i("Receiver","got event");
    ComponentName componentToDisable = new ComponentName(context,BlockableComponentActivity.class);
    context.getPackageManager().setComponentEnabledSetting(componentToDisable,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}

:

<receiver android:name="PackageChangeReceiver">
<intent-filter>
    <action android:name="android.intent.action.PACKAGE_ADDED"/>
    <action android:name="android.intent.action.PACKAGE_REPLACED"/>
    <action android:name="android.intent.action.PACKAGE_REMOVED"/>
    <data android:scheme="package"/>
</intent-filter>

+5

All Articles