Trying to start a service on boot on Android

The other answers look good, but I thought I’d wrap everything up into one complete answer. You need the following in your AndroidManifest.xml file: In your <manifest> element: <uses-permission android:name=”android.permission.RECEIVE_BOOT_COMPLETED” /> In your <application> element (be sure to use a fully-qualified [or relative] class name for your BroadcastReceiver): <receiver android:name=”com.example.MyBroadcastReceiver”> <intent-filter> <action android:name=”android.intent.action.BOOT_COMPLETED” /> </intent-filter> … Read more

How to use LocalBroadcastManager?

I’ll answer this anyway. Just in case someone needs it. ReceiverActivity.java An activity that watches for notifications for the event named “custom-event-name”. @Override public void onCreate(Bundle savedInstanceState) { … // Register to receive messages. // We are registering an observer (mMessageReceiver) to receive Intents // with actions named “custom-event-name”. LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(“custom-event-name”)); } // Our … Read more

Start and Close single Activity from BroadcastReceiver

You could try to directly kill an activity by calling a static method in that activity: Activity A should have a variable static ActivityA activityA; In onCreate state: activityA = this; and add this method: public static ActivityA getInstance(){ return activityA; } In activity B, call the fuction getInstance() ActivityA.getInstance().finish();