Skip to content Skip to sidebar Skip to footer

Nullpointerexception At Sendbroadcast() From Service To Activity

I have a Service class and an main Acitivity class which is supposed to receive broadcasts from the Service class with method sendBroadcast. It crashes when running the method send

Solution 1:

Try changing your sendBroadcast call to: context.sendBroadcast(intent);

Solution 2:

From your stack trace, it appears you are somehow directly referencing your BTService service. Since you cut your onCreate() short I can't be certain how you are doing it, but I will take a guess.

Did you instantiate this service directly inside of your activity (use new BTService())? If so, then the reason you are getting this error is because your Service has no context bound to it. You must let Android create your service for you by calling startService() or bindService().

Solution 3:

Try to add myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

Post a Comment for "Nullpointerexception At Sendbroadcast() From Service To Activity"