Android Question [SOLVED] Using StartAtBoot successfully but not getting the expected intent

Sandman

Expert
Licensed User
Longtime User
I have a service (not Starter) that I'm successfully starting at boot.

However, instead of getting the expected intent (android.intent.action.BOOT_COMPLETED) it's always empty.

I don't really know how to approach this. What could cause me not getting the intent?

I'm testing this on a Nexus 5X running Android 8.0.0.
 

Sandman

Expert
Licensed User
Longtime User
I whipped up an empty project with an extra service just to exclude other factors.

B4X:
#Region Service Attributes 
    #StartAtBoot: True
#End Region

Sub Process_Globals
End Sub

Sub Service_Create
End Sub

Sub Service_Start (StartingIntent As Intent)
    ToastMessageShow(StartingIntent, True)
End Sub

Sub Service_Destroy
End Sub

To my surprise, this actually produced a toast with the correct intent. (I rebooted twice to verify it wasn't a single, lucky break.) So I must have done something in my real project to cause the intent to be empty. How is that even possible? What could cause this as a side-effect?
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Just a short update. I've replaced the service in my real project with the skeleton one above. That works just as expected, the toast shows the correct intent after boot.

I'll keep on investigating, and will report back once I crack this.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
...and solved. Yep, it seems to work as expected now. Ultimately it came down to what I had in the Service_Start. I shuffled things around a bit and rewrote small things, and then it started working as expected.

The bad news is that I'm not sure what actually solved this. And I've already spent way too many hours with this problem, and probably restarted my phone more than 100 times. So the best help I can give is to say that something inside Service_Start caused the intent to it to be empty. And just to be super clear: I did not mess with the intent in any way, in my old - broken - code I showed the intent using a toast the first thing, and it showed up as empty.

It doesn't make sense to me, not even a little bit. But that's where I'm at. Hopefully that can be a clue to somebody in the future facing this problem.
 
Upvote 0
Top