8

I've been trying to work out this issue the whole day without luck. Here's what happens: I tested my app and it worked perfectly, then I unplug the phone and leave the app in the background, and after a few minutes, it doesn't start anymore and must be force closed. Strangely enough, the problem doesn't happen when the device is plugged in: I left it there for 2 hours straight and it worked, then I unplugged it and 5 minutes later the app was frozen. I suspect it has something to do with the phone entering deep sleep (I'll try with a wakelock just to be sure). When I plug in the phone and look at logcat, all I see are warnings that the app must be force closed, and this suspicious looking line:

Activity reported stop but no longer stopping

What does it mean? I didn't stop the activity, it's running in the background, and it wasn't killed by the system either because when that happens the app doesn't freeze, it gets killed and must be restarted.

I've never had this problem before and I can't find anything on the internet about this issue: have you ever encountered something like this? What should I do?

Guilherme
  • 43
  • 14
dosse91214
  • 561
  • 1
  • 5
  • 17
  • You could get a rooted device and connect it with some wireless ADB connection so that you could keep checking logs even when the deice is unplugged, or try to dump your log into a folder on your phone so you can read it and see where your are crashing. – zgc7009 May 02 '14 at 15:30
  • Are you following the Activity LifeCycle methods properly? Would be great if you post some code. – Skynet May 02 '14 at 15:39
  • as far as I know, I followed it. There's onCreate method that does absolutely nothing but set the layout xml file and an onResume method that populates a list, and this one works. I didn't even touch onStop. – dosse91214 May 02 '14 at 15:43
  • I'd post some code but I don't know what to post because I don't know where it fails. Should I post the entire project? – dosse91214 May 02 '14 at 15:43
  • experiencing the exact same problem only developing my app in Delphi – Johny Mar 19 '19 at 10:14
  • @Johny you did see dosse91214 *answered* his own question ?, *fixed* the problem, but *did not understand* **how/why** his fix worked. He says ***"A wakelock fixed the issue."*** There is not enough **info** in the question to try and reproduce the problem, let alone fix it. – Jon Goodwin Mar 21 '19 at 15:19
  • fetch ANR logs from device and check I am sure you will getting something. – Imtiyaz Khalani Mar 26 '19 at 04:59
  • You can also switch adb to a wireless mode, to keep debugging when unplugged https://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp/44460975 – mksteve Mar 26 '19 at 09:15
  • Was the *stay awake* in developer options set to enable when you plugged in your phone? – Harvey Mar 26 '19 at 09:46

1 Answers1

1

While charging and usb debugging many power management restrictions don't apply. Here check it. In each android version, there are more restrictions coming on background processes for power management.

My prediction is when you unplug your app encounters with some of those restrictions and due to lack of any wakelock acquired, your app is not able to use any cpu. For example, if you have a service using a handler with post delayed, it never does the job until some cpu time gets elapsed. Check its documentation.

Mertcan Çüçen
  • 466
  • 3
  • 13
  • The thing is, i'm just launching the app, where the first page is a log in form and then just hitting the home button to put the app in background mode. At this point, my app did nothing still, no attempt to connect, fetch data.... Why would it require any CPU in that case? Also i'm not using any wakelock in my app. But is it really the proper way of handling such a situation? – Johny Mar 19 '19 at 12:10
  • Are you certainly sure that you don't start any async job or background services etc.? – Mertcan Çüçen Mar 19 '19 at 12:23
  • i went over the entire code. I'm positive no service or background task is being executed. My suspicions are currently directed towards the fact that i'm using a single form with page-control maintaining up to 10 tab pages. Also i have 4 memory tables located on this form which is used to support data fetched from the server and displayed in list-views. Maybe the fact that i'm putting all the load on a single form is eating up much memory, thus triggering this behavior?? I'm out of clues at this point. – Johny Mar 22 '19 at 13:30