Kevin Pione
Kevin Pione

Reputation: 299

Dealing with paused or stopped activities in conjunction with services

I currently have a foreground service fetching GPS co-ordinates and sending them to an activity which calculates distance, time and speed. I want to constantly be getting this data and sending it until the user presses a stop button.

However, whilst I am using a foreground service to get the information, I'm worried my activity won't receive it, if it's been minimised and executed onPause or onStop methods.

Therefore is there a way to stop the activity from pausing or stopping. Or perhaps a better alternative would be, how to store the data in the service and send it/update once the activity has resumed?

Upvotes: 1

Views: 62

Answers (1)

Adam Arold
Adam Arold

Reputation: 30528

You may push them into a Queue or something similar (maybe SQLite) and when your Activity is not paused/stopped you can just pop entries from your Queue.

You can't stop the Activity from getting paused/stopped since this is controlled by the Android framework.

So generally in cases like yours a FIFO data structure usually solves the problem.

Upvotes: 1

Related Questions