I programmed a boot up receiver to start a service, but the service is not starting. I don't even think the broad cast receiver is receiving any intents.
I set the permission
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
I declared the receiver in the manifest
<receiver android:name=".ServiceStarter">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Here is my broad cast receiver class. I'm not logging any output in this class after boot up.
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class ServiceStarter extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent("com.prac.test.MyPersistingService");
i.setClass(context, MyPersistingService.class);
context.startService(i);
Log.v("TAG","Broadcast received"); //Doesn't print anything
}
}
Here is my service class. None of the toasts are displayed after boot up.
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class MyPersistingService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
Toast.makeText(this, "Service created!", Toast.LENGTH_LONG).show(); //Doesn't show up
}
@Override
public void onDestroy() {
Toast.makeText(this, "Service stopped", Toast.LENGTH_LONG).show(); //Doesn't show up
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "Service started by user.", Toast.LENGTH_LONG).show(); //Doesn't show up
Log.v("TAG", "Service started");
}
}