开发者

How to run a continuous process

开发者 https://www.devze.com 2023-02-12 03:07 出处:网络
I\'m working on an Android app to be used in an experiment we are running in our lab. The application monitors the user开发者_开发知识库s movement using the accelerometers, performs calculations on th

I'm working on an Android app to be used in an experiment we are running in our lab. The application monitors the user开发者_开发知识库s movement using the accelerometers, performs calculations on this data at a regular interval, and writes the results to a file.

I'm currently having a very difficult time trying to find a way to run this process for the 15-20 minutes our trials require without it being killed. Despite declaring applications persistent, trying various service approaches (startForeground(), START_STICKY, ..), etc... I cannot seem to keep the Android OS from deciding to pause or kill my service/process.

I've done some research and the only advice I can find is how to set up your processes to gracefully recover from being killed, however I cannot afford to have gaps in my data and therefore need this process to run continuously.

Could someone point me in the right direction?


From documentation I get the impression that if you want to have a service that will only be killed in extremely low memory situations you need to:

  • startForeground() (you have done that)
  • START_STICKY (you tried that too) or START_REDELIVER_INTENT (restarts service if it is killed, but that leaves gaps in your data)
  • run all its processing in a separate thread
  • use Context.startService() to start service

The only sure way is to have it as a system daemon.


The best solution I could come up with for my problem is increasing the screen sleep delay on the device to 30 minutes and pray no buttons were pressed during our trials.

0

精彩评论

暂无评论...
验证码 换一张
取 消