I am building an app, in which i am displaying some data which i am getting from some url using asynctask & i am updating the data after every 5 seconds using handler and runnable and i am playing a sound every after 5 seconds after receiving data. it is working fine. Now i want that, when i close the app, it should keep receiving data and play that sound when new data is recieved. How can i do that ? I have found that i have to use service for that, but not getting any clear solution, i am very new to android, so any help would be appreciated.
Asked
Active
Viewed 425 times
-2
-
2Use a foreground service – denvercoder9 Sep 23 '19 at 09:23
-
ok,, it will be helpful if you provide some sample code ... – Wasim Khan Sep 23 '19 at 09:29
-
https://developer.android.com/guide/components/services#Foreground – denvercoder9 Sep 23 '19 at 09:36
-
https://stackoverflow.com/questions/6397754/android-implementing-startforeground-for-a-service – denvercoder9 Sep 23 '19 at 09:37
1 Answers
0
You should use startService()
method in your activity.
And you should create your Service
in which call startForeground()
method to prevent the system from closing the service. When in service you may do periodic tasks.
For detailed explanation please visit this page.

Shadkirill
- 92
- 6