1

I have developed an application that is used very intensively for hours, makes a lot of web services calls, uses a lot of async tasks and does a lot of operations on an sqlite database. The problem is that absolutely randomly the display dims, as if it goes in power saving mode (this is happened also when the battery was charged) and the UI does not respond at all (the log written for buttons click are not written). If I click the home button the phone works correctly and every app works fine. If I go back to my app the display dims again. I really don't have any idea about the cause of this behavior, I really hope some of you can help me because my boss wants an explanation because the customer wants an answer.

EDIT: I've noticed that when the problem occurs, it's just after unlocking the screen, so it should have something to do with app resuming, but I don't really have any idea of what is causing this behavior.

Gijs
  • 5,201
  • 1
  • 27
  • 42
Apperside
  • 3,542
  • 2
  • 38
  • 65
  • 1
    seems to me like you just need to acquire a wakelock to prevent the device screen from timing out after inactivity. – FoamyGuy Apr 30 '13 at 19:11
  • what do you exactly mean for "screen timeout after inactivity" ? – Apperside May 01 '13 at 09:48
  • If you turn the screen on and leave your device sitting for a few moments without doing anything else on it the screen will dim and then eventually turn off at some point. How long it takes is a user setting. If you acquire a wakelock in `onStart()`, and then release it in `onStop()` it will prevent the device from "going to sleep" while your app is running. – FoamyGuy May 01 '13 at 13:05
  • my problem is not the screen timeout, which is every phone's normal behavior, but the fact that the display dims just on my app, causing my app (ONLY MY APP) to be touch unresponsive at all, meaning that it's impossibile to click everything. the only solution is to kill the app and start it again – Apperside Jun 12 '13 at 11:29
  • Did you have any log in OnResume? Did it get called? What if you switch to other application and come back? Is the screen goes un-reactive then? – Naresh Jul 15 '13 at 06:59
  • Are you logging what the app is doing at this point? Do you log the start and end of each AsyncTask and Web access to see what is going on at the time? – Neil Townsend Jul 15 '13 at 14:47
  • I am just guessing this as a Test Case. Since you have said you are using a lot of AsyncTasks, you might have shown a invisble/transparent ProgressDialog which gives an effect of dimmed display and if `setCanceledOnTouchOutside` is set to false then it does not allow you to touch on your activity. Its difficult to tell because you have not provided any code. – Laksh Jul 15 '13 at 15:47
  • @Laksh I does not make sense to provide code, because, by the moment it does not happen every time in the same point, I should post the entire project code. What I can tell to you is that yes, I use ProgressDialog, but with a message, which is not shown when the problem occours – Apperside Jul 16 '13 at 07:25
  • @NeilTownsend In that moment the app is doing nothing, I dont't think the problem are the AsyncTasks, by the moment that when the screen is turned off, there is no running async task, so the problem can't by caused by them – Apperside Jul 16 '13 at 07:26
  • @NareshR the onResume is correctly called, and if I switch to other apps the phone works perfectly, going back to my app the problem comes back – Apperside Jul 16 '13 at 07:29
  • @SimonVeloper You add a `onTouchListener` to the root activity and print logs when that screen is touched. It might give an insight of whether that activity got the touch communicated or is there any transparent screen hiding that one. – Naresh Jul 16 '13 at 07:59

3 Answers3

1

It seems that some operations may be blocking the main UI thread and the app goes to not responding state. Check if any such intensive operations are done in UI thread.

jaibatrik
  • 6,770
  • 9
  • 33
  • 62
  • 2
    in the case i'm wrong doing too much work in the UI (but I don't think, I was very careful about this), shouldn't i receive an ANR message? because when the problem occurs, no ANR message is shown, even if i wait a lot of minutes – Apperside May 01 '13 at 09:47
0

As jaibatrik says, this might be caused by doing too much work in the UI thread rather than in background threads, AsyncTasks etc. One way this may be achieved which is less obvious is if all the work is correctly done in a background thread (of some type) but a UI thread operation is waiting for the outcome of a background thread operation.

Neil Townsend
  • 6,024
  • 5
  • 35
  • 52
0

you could prevent display dim like this. ll.setKeepScreenOn(true);

you should handle onresume(), onpause() & co. maybe you create memoryleaks within your backgroundtasks or services.

ornay odder
  • 135
  • 5