I am trying to make a broadcast receiver that receives BOOT_COMPLETED when the decvice is powered up; and eventually I want to launch my application. Here's my code:


BroadcastReceiver mReceiver = null;
protected void onCreate(Bundle savedInstanceState) {

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    mReceiver = new Receiver();
    registerReceiver(mReceiver, filter);


public class Receiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        // display received action on the screen


<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <receiver android:name="com.test.project.Receiver">
            <action android:name="android.intent.action.BOOT_COMPLETED" />

The problem is,

My broadcast receiver well receives SCREEN_ON and SCREEN_OFF nicely. But when the device is restarted, the application gets unfortunately stopped because the Receiver does not exist. The error message on my LogCat is:

java.lang.RuntimeException: unable to start receiver: java.lang.NullPointerException

In fact, this error message is not very surprising because my application has been terminated during device reboot. What should I add or modify in my code? Please help


StaticUtil.toastString(intent.getAction()); made error because the application was turned off so there is no such function to call in memory.

Everything works except this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.