Loric
Loric

Reputation: 1708

android BOOT_COMPLETED not received if not activity intent-filter

I set up a simple app. I wan't to hide it from the drawer and I want to add a Boot Receiver to launch a service.

To hide the application, I read that I had to remove this from the manifest

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

But when I remove it, the boot receiver doesn't work anymore.

I added the permission under the manifest tag

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

and my receiver under application

<receiver android:name="com.example.receiver.BootReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

And in the receiver code, there is just a Toast

public class BootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "Boot Received", Toast.LENGTH_SHORT).show();
    }
}

Why couldn't I set the boot receiver AND the hidden app from drawer?

Thanks

Upvotes: 1

Views: 1427

Answers (1)

Caner
Caner

Reputation: 59268

Starting with Android 3.1 all applications, upon installation, are placed in a "stopped" state.(This is the same state that the application ends up in after the user force-stops the app from the Settings application.)

Android stopped state

While in "stopped" state, the application will not run for any reason, except by a manual launch of an activity. (Meaning no BroadcastReceviers(ACTION_PACKAGE_INSTALLED, BOOT_COMPLETED etc.) will be invoked, regardless of the event for which they have registered, until the user runs the app manually.)

This is an anti-malware move by Google. Google has advocated that users should launch an activity from the launcher first, before that application can go do much. Preventing BOOT_COMPLETED from being delivered until the activity is launched is a logical consequence of the that argument.

More details about this:
http://developer.android.com/about/versions/android-3.1.html#launchcontrols
http://commonsware.com/blog/2011/07/05/boot-completed-regression.html
http://devmaze.wordpress.com/2011/12/05/activating-applications/

Upvotes: 6

Related Questions