0

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="8" />
  <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);
  }
}
Thomas Economous
  • 141
  • 1
  • 2
  • 8
  • You might try adding the targetSdkVersion to 11 or 12. I know that Android uses compatibility code when using older sdk applications on new sdk devices. All targetSdkVersion does is say you've tested up and through a specific API so Android is ok to remove the compatibility code and run the application fully on the newer sdk. – Spidy Jun 30 '11 at 01:22
  • Spidy, I've tried 8, 9, 10, 11, and 12. The app still behaves the same way in 3.1. Thanks for the input though. – Thomas Economous Jun 30 '11 at 17:21

1 Answers1

4

I found out this is a policy change in 3.1. An app remains inactive after installation until the user launches it for the first time.

Thomas Economous
  • 141
  • 1
  • 2
  • 8