Android Question [SOLVED] Broadcast receiver and event handling in same service ?

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
It is more than probably an old error of mine that only comes to the surface from today. Please, I would like to be sure the workaround I put is the really one I had to use.

I have registered a broadcast receiver (SMS data) in the manifest, pointing to a service. So the service is started each time a SMS data is received. But in the same service, I am handling the data. When a new SMS is received while the data from a previous SMS is processed, the service crashes (about a list not initialized, the one containing the intent information ~~~ probably the old ones). Till today, it has worked without any problem and the only thing I changed was to try the app on Marshmallow.

So, I think that I have not well thought about the fact that the main process was working and that the system won't wait to restart the service while it is running. My workaround is now to create a class and initialize it for each SMS data received.
For the moment I have no more crash but, I would like to be sure to have used the correct solution.

Many thanks
 

JordiCP

Expert
Licensed User
Longtime User
It makes sense to me, since the solution seems to involve a local copy of the relevant info (the intent or its contents) to be processed each time. So the key is that the process will depend only on local vars.
Also, an alternative would be to isolate everything even more and process it perhaps in another service, with CallSubDelayed, passing the locally copied info as parameters. This way, there would be no global instances and the 'work to do' (again with its parameters) would be in the call stack waiting to be processed.
I may be missing other factors, but regarding the 'local-global' problem, seems ok.
 
Upvote 0
Top