i'm developing an Android App for mobile sensor monitoring (accelerometer, gyroscope etc). The application is build on a class that extends from BroadCastReceiver and has communication with a service (a class that extends from Service) which is responsible of recording the sensor data when some android events occurs. When the app is running in the background works nice until I kill the activity (in this activity the user can adjust some params). I want to continue recording after the app is killed, how to fix it? Thanks!
Asked
Active
Viewed 1,175 times
1
-
what service did you start service with? I suggest that override onstartcommand with START_STICKY would be helpful – iroiroys May 04 '16 at 10:01
-
Service is used to perform long-term background processes and STICKY service ensures to start back again if killed. I think it will provide help as your requirements – Hassan Jamil May 04 '16 at 10:23
-
Thanks to you both, with return START_STICKY in the onstartcommand works nice. Also i need to use PowerManager to prevent the Android CPU from going to sleep. – Ignacio Melero Jul 04 '16 at 10:37
3 Answers
0
You can use both of this framework to schedule your service to start at the time that you want. Like on every hour or so
http://developer.android.com/reference/android/app/job/JobScheduler.html http://developer.android.com/reference/android/app/AlarmManager.html
but remember that if someone will go to task manager and kill your process there is no possibility to avoid that.
cheers

wojciech_maciejewski
- 1,277
- 1
- 12
- 28
0
Solved with return START_STICKY (onstartcommand() of the service) and PowerManager inside the service to prevent the Android CPU from going to sleep. Thanks to all!!

Ignacio Melero
- 51
- 1
- 4