I am new in android and I don't know how to do this, I want to create a background service, There is two main component in my app one is Button (Start Earning) and another is TextView (Points). I want to create service like if User Open app and Click on Start Earning Button then the the points in TextView wants to Increase Continuously For 1 Hour (100 Points In 1 Hour). then after 1 hour I want to stop that service automatically even if app is closed
Example Is In This Screenshot.
Pls Help Me I Search Every Where (Google,Stackoverflow,Github,etc.) But I Don't Get Any Answer.
The service you are looking to use here is a broadcast service, which broadcast how much time has been passed after button has been pressed. So you can have a broadcast service, which has a
CountDownTimer
for counting down 1hr time. Then you can broadcast the message (containing the points) after a particular time (like after each minute or seconds or after an hour) based on your need. In your fragment/activity you will have an broadcast listener, which will listen to the broadcasted messages (points) and update the UI. You can refer to https://stackoverflow.com/a/22498307/5309486 answer for the implementation details.