Android Question Service module and best practices

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
I have a service module that get four banners on the Internet and displays them in an activity.

Many things can happen:
For example, the device is not still connected to the Internet, the connection is too slow, server error, activity is paused...

So the service is in background trying to download.

What is the best practice? the service module wait for next attempt (30 seconds) or try continuously, or just cancel?

Is there any reason to wait for the next attempt? This can change the battery consumption?

Thank you.
 

KMatle

Expert
Licensed User
Longtime User
No problem. With

B4X:
Sub Service_Start (StartingIntent As Intent)

If BannersLoaded = False
    LoadBanners 'it's a Sub
    StartServiceAt("",DateTime.Now+30000,True)
End if

End Sub

you can check if the banners are loaded, otherwise the service starts again in 30 secs. If everything was ok then set BannersLoaded to True.

Additionally check how often this is done. You can cancel if after x tries or increase the time the service starts again.

I would decrease the timeout for the job with

B4X:
Jobxxxx.GetRequest.Timeout=3000

Here the timeout is decreased from 30 to 3 seconds (30 seconds is a very long time).
 
Upvote 0
Top