I have an application without launcher activity that works properly from Android 1.5 to Android 2.3.4. It is started by my broadcast receiver. However, on Honeycomb (Motorola Xoom), my broadcast receiver doesn't work at all (it does not catch any intents). If I add launcher activity to my manifest:

<activity android:label="@string/app_name" android:name="com.myapp.MainActivity"> 
<intent-filter> 
<action android:name="android.intent.action.MAIN" /> 
<category android:name="android.intent.category.LAUNCHER" /> </intent-filter> 
</activity>

Then my app works properly (broadcast receiver catches all necessary intents and starts my services).

I would be very grateful for help!

有帮助吗?

解决方案

Are you running Honeycomb 3.1 or above? If yes take a look here. When your application is installed, it is in stopped state. When the application is first launched, it is moved out of stopped state.

A application in stopped state won't get started by all broadcast intents. The sender of the broadcast intent has to specify the Intent.FLAG_INCLUDE_STOPPED_PACKAGES flag if it wants to launch stopped applications too.

Intent intent = new Intent(MY_INTENT_ACTION);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(intent);

If you can't change the code which sends the intent, your best bet would be to keep the launcher activity. Whenever the user launches your application after installation, it will be moved out of the stopped state and you will start receiving broadcasts.

Note the the user can move your application back to the stopped state from Manage Applications in device settings.

其他提示

On Android 3.1 and higher, BroadcastReceivers will not be invoked until the user has started the application at least once by some other means, such as launching an activity.

Since users tend to get very confused by applications that do not have an activity, you really should have had an activity in the first place, for online help if nothing else. With Android 3.1, that is even more important.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top