1

I see a lot of examples of onRecieve() and BroadcastIntent etc. Still not sure how to do it. The Toast example below still does not work. I have an app with 2 activities. I would like to start the main activity on system start. So when the phone is unlocked my app will be running.

public class MainActivity extends AppCompatActivity {

Intent intent;

public class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();
        //onCreate(savedInstanceState);
    }
}
}

    <receiver android:name=".MainActivity$MyReceiver" >

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

    </receiver>   

The examples I see is with Toast and not with how to have that same app started.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Zod
  • 87
  • 3
  • Boot complete is for when the device powers on or restarts not when the device unlocks – JRowan Jan 07 '19 at 16:04
  • public class MyReceiver Should be public static class – EpicPandaForce Jan 07 '19 at 18:26
  • EpicPandaForce is right. That Receiver class would have to be `static` to allow it to be instantiated from a manifest entry. Also, in that case, you will not have access to `MainActivity` or its members, so you won't be able to call any methods there, though you should not be calling `onCreate()` yourself anyway. – Mike M. Jan 07 '19 at 20:34

0 Answers0