Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I'm developing an app for my tablet that is to turn on the screen when I rotate it to the vertical (the power switch is dodgy). It has an optimization to turn off the sensor from 22:00 to 06:30. The app works most of the time. However sometimes it fails. For example this morning I picked it up at 07:10 and the screen came on as expected. I put it down for about a half an hour and when I picked it up again it did not come on. I plugged in the power and it came on. I stopped my service and restarted it then and it has been running fine: pick up and it comes on when the screen has gone off.

Looking at the logs I see that the system stops the service frequently(maybe every 30 minutes) and then restarts it, passing a null intent to the onStartCommand() method. I've used SharedPreferences to save the app's state and am able to successfully restart the app where it needs to be.

My question: why didn't the app work this morning after it had worked on the first pickup of the morning? Any ideas on how to debug this or any work-arounds?

Thanks,
Norm
Posted
Comments
Sergey Alexandrovich Kryukov 6-Oct-14 16:13pm    
This happens because you have some bug. Due to nice comfortable weather, my access to your system is somewhat limited, so I cannot fix it. :-)
—SA
NormR1 10-Oct-14 12:32pm    
How is the weather now? Any suggestions for How do to find the bug?
NormR1 13-Oct-14 7:19am    
How is the weather now?
NormR1 8-Oct-14 18:18pm    
Thanks for the response.
It's a very elusive bug. The code works so many times and fails so few times that I'm not able to come up with a debugging scheme to find out a reason or pattern for the failure.
Do you have any suggestions?

Something I've observed by looking at the logs is that the system restarts my service (passing a null intent to the onStartCommand() method) very soon after I have plugged in the tablet to turn on the screen. How would a bug in my code cause that?

Another observation: the system often restarts my service 5 seconds after the AlarmReceiver is supposed to receive an alarm: at 22:00:05 for an alarm set for 22:00:00.
NormR1 16-Oct-14 7:50am    
The program continues to work differently each morning. Yesterday morning it worked as desired. This morning there was a delay in starting the service after I rotated the tablet. Why would the Android system restart my service when I lifted and rotated the tablet? My service should have been executing and receiving Sensor values which it would use to turn on the screen.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900