Android Question Background operation

tufanv

Expert
Licensed User
Longtime User
Hello,

I just saw Erel’s Background location tracking tutorial. I have a financial app where users can create their portfolios and check their investment value inside the app. I want to ask if it is possible with background tracking:

1) can I calculate the portfolio value and send it to server at a specific time?
2) what happens if the app was killed from the background. Would it still do this?

Thanks,
Tufan
 

drgottjr

Expert
Licensed User
Longtime User
you mean a service. background tracking uses a foreground service.
the tutorial and the link in it should help you. just remove the location
parts and insert okhttputils2 to post some data to the server every so
often (or to download some data).

get something going, and when there's an error post your code for
some help.

you can also start with a simple service with a timer to see how it
works. then add networking once you're good. if you've never used
services before, you should start that way until you're comfortable.
just remember there can be no user/gui stuff in the service (initially,
you use log entries to keep yourself informed how things are going).
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Trying to keep the app running in the background is likely to fail. You can start it every x minutes with StartServiceAt.

The best solution however, is to move the calculations to a server and send push notifications to the device when needed.
Yes it seems like that. I wanted to avoid it as there are too many users but I will send the portfolios to server and make the calculations there.
 
Upvote 0
Top