Broadcast Receiver not working immediately after package installation

3538 views
Skip to first unread message

Thomas Economous

unread,
Jun 30, 2011, 2:01:54 PM6/30/11
to Android Developers
I am currently working on an app that receives the BOOT_COMPLETED
action using a Broadcast Receiver. The receiver is statically
registered in the AndroidManifest.xml.

It works on the next boot after installation for android 2.2 but not
3.1. With 3.1 I have to start the app once before the broadcast
receiver gets the BOOT_COMPLETED action when booting.

I suspect that something changed in 3.1 that is causing my receiver to
be inactive until the app is started once.

Has anyone ever seen this before or know how to stop this behavior?
Any Help would be greatly appreciated. Thanks, Tom.



AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.receiver"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="12" />
<uses-permission
android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /
>
</intent-filter>
</activity>
<receiver android:name="TestReceiver" android:enabled="true">
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>



TestReceiver.java:

package com.test.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class TestReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("TestReceiver", "onReceive() was called");
}
}



MainActivity.java:

package com.test.receiver;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

Mark Murphy

unread,
Jul 4, 2011, 7:29:44 AM7/4/11
to android-d...@googlegroups.com
On Thu, Jun 30, 2011 at 2:01 PM, Thomas Economous <econ...@gmail.com> wrote:
> I am currently working on an app that receives the BOOT_COMPLETED
> action using a Broadcast Receiver. The receiver is statically
> registered in the AndroidManifest.xml.
>
> It works on the next boot after installation for android 2.2 but not
> 3.1. With 3.1 I have to start the app once before the broadcast
> receiver gets the BOOT_COMPLETED action when booting.
>
> I suspect that something changed in 3.1 that is causing my receiver to
> be inactive until the app is started once.
>
> Has anyone ever seen this before or know how to stop this behavior?

I can confirm the behavior, new to 3.1 (3.0 does not exhibit this
behavior). I suspect it cannot be stopped. This feels like a
security-related change.

Anyway, I filed an issue on it:

http://code.google.com/p/android/issues/detail?id=18225

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training in London: http://bit.ly/smand1, http://bit.ly/smand2

Thomas Economous

unread,
Jul 6, 2011, 6:34:05 AM7/6/11
to android-d...@googlegroups.com
Someone stated that this is an intentional 3.1 policy change in another thread. Not sure if there is a good place to find information about changes like this.


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-d...@googlegroups.com
To unsubscribe from this group, send email to
android-develop...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Mark Murphy

unread,
Jul 6, 2011, 6:43:08 AM7/6/11
to android-d...@googlegroups.com
On Wed, Jul 6, 2011 at 6:34 AM, Thomas Economous <econ...@gmail.com> wrote:
> Someone stated that this is an intentional 3.1 policy change in another
> thread. Not sure if there is a good place to find information about changes
> like this.

Got a link to that thread?

Android App Developer Books: http://commonsware.com/books

Reply all
Reply to author
Forward
0 new messages