Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having my app run for several hours causes android phone to freeze

Tags:

android

freeze

Whenever I leave my app running for awhile (~9 hours last time) whatever activity the phone has up will stop responding and need to be force closed, after which there's just a black screen below the slide down notification area and pressing back or home changes nothing. I cannot turn the phone off normally either, as it just spins endlessly when trying to turn the phone off. I need to remove and reinsert the battery.

My app has a background service which monitors for a bluetooth device and runs accept threads with 30 second timeouts. I believe I'm handling them properly as there's only ever 1 shown in my debug screen. I have seen this phone freezing behavior while having the device connected for the entire duration and not having it connect at all.

I have tried keeping the phone connected to logcat to see what happens when the phone freezes up but it always stops receiving updates from the phone after some time, maybe an hour or two at best? Hard to estimate since I'm usually doing something else while waiting.

Does anyone have any tips for what could be causing this or how I can get some additonal feedback to work with?

like image 567
Bryan Avatar asked Nov 14 '22 02:11

Bryan


1 Answers

if your service runs in the background , the OS might kill it after some time , and you must know how to handle it within the service .

services that do a lot of work will be good candidates of being killed .

if you wish your service to do long work (30 seconds is quite a long time) , you should set your service as a foreground service , with a notification .

if you don't wish your service to be a foreground service , try to recover your state when being killed , and try to optimize your code further .

for more information of how services run on android , read this link .

like image 51
android developer Avatar answered May 11 '23 19:05

android developer