Android - [Xoom/Honeycomb] application without LAUNCHER activity does not work
Asked Answered
C

2

6

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!

Charmainecharmane answered 8/9, 2011 at 13:53 Comment(2)
Where is your broadcast receiver defined?Retractor
@Jon Willis: Receiver is defined in manifest. CommonsWare and Gaurav have explained the problem. Thank you for your help!Charmainecharmane
P
10

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.

Pownall answered 8/9, 2011 at 15:0 Comment(0)
U
4

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.

Unkindly answered 8/9, 2011 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.