0

I've a reciever

public class MyBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent myStarterIntent = new Intent(context, MainActivity.class);
        context.startActivity(myStarterIntent);
    }
}

and have modified the AndroidManifest.xml, adding these lines

<receiver
    android:enabled="true"
    android:name=".MyBroadcastReceiver"
    android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
    android:exported="true">

    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>

</receiver>

to section. The application still does not start on system boot..any ideas appreciated. At least how can I monitor what is going on after device reboot (because I cant just use breakpoints in that case)

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Omkommersind
  • 276
  • 5
  • 13

1 Answers1

1

You need to provide Intent.FLAG_ACTIVITY_NEW_TASK flag when starting activity from BroadcastReceiver.

Intent myStarterIntent = new Intent(context, MainActivity.class);
myStarterIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myStarterIntent);

This is how you can test the BroadcastReceiver.

Community
  • 1
  • 1
K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33