Why is my Service occasionally restarted? - Android Software Development

Program's purpose: turn on screen when tablet is rotated to vertical with an optimization to sleep between 10PM and 6:30AM
Outline of program's action
MainActivity starts Service
Service then:
registers broadcast receiver for Screen On/Off events
sets alarm for stop time
When screen goes Off: receiver sends ScreenOff message to Service via Intent
Service starts Sensor listener for orientation
When orientation changes to vertical:
Service sets Screen On
When receiver gets Screen On - sends ScreenOn message to Service via Intent
When Service gets ScreenOn message - stops Sensor
When Service gets Alarm message via Intent from AlarmReceiver:
If SetOff - turns off Sensor and Wifi, sets Alarm for start time
If SetOn - turns on Sensor, sets Alarm for stop time
The problem:
Sometimes the Service is stopped before the stop alarm is received and the alarm receiver is not called.
However the Service is restarted at very near to the time when the alarm is set for: onCreate() is called and then onStartCommand() is called with a null Intent and with the startId value that follows the last one passed to onStartCommand() before the restart.
The program works as expected about half the time.
Some lines from the Logcat gathered by the adb logcat command when tablet connected by USB for when Alarm was not sent:
I/ActivityManager( 9802): Killing 5496:com.normsstuff.wakeup/u0a10223: remove task
W/ActivityManager( 9802): Scheduling restart of crashed service com.normsstuff.wakeup/.ScreenOnOffService in 5000ms
I/ActivityManager( 9802): Start proc com.normsstuff.wakeup for service com.normsstuff.wakeup/.ScreenOnOffService: pid=2072 uid=10223 gids={50223, 1015, 1028}
I/ActivityManager( 9802): No longer want com.normsstuff.wakeup (pid 2072): empty for 1818s
W/ActivityManager( 9802): Scheduling restart of crashed service com.normsstuff.wakeup/.ScreenOnOffService in 5000ms
I/ActivityManager( 9802): Start proc com.normsstuff.wakeup for service com.normsstuff.wakeup/.ScreenOnOffService: pid=5387 uid=10223 gids={50223, 1015, 1028}
Related post: http://stackoverflow.com/questions/26048934/looking-for-debugging-ideas

Related

Alarm clock feature not working properly

My alarm clock feature will not automatically turn on my MDA in the morning. Once I physically turn the device on, the clock on the today screen automatically updates to the current time, and the alarms go off. This was not the case in the past. The only software I have installed that could be causing the problem is Smartskey. Any ideas anyone?

[Q] TV out with screen timeout

Would it be possible for somebody to release a mod that when you enable TV out, your phone's screen will still timeout at whatever time you have it set (ex: 30sec), but what is being shown through TV out will still be on? If you were to touch the screen it would turn on again, allowing you to pause/ff/rw/stop whatever you're watching. I think this would help a lot with battery life when you're displaying something on a larger screen and don't need to see it on your phone.
In Android, when the screen turns off due to a timeout or lock, it will suspend things like media, webkit stuff, and the UI. So the only way this would work out is if someone modified the media library so it doesn't suspend when the "screen off" event happens.
BUT! I have used an application (requiring root) that will set the screen brightness below the system's limit, so instead of being restricted to 20 out of 255 as the minimum, you can set it to 0.
With this, it is possible for an application to detect user inactivity, and set the brightness to 0/255 after inactivity, while you keep the Android screen timeout setting to "Never" so that the media doesn't suspend and everything keeps running.

Timer bug

I observe the following weird (and annoying) bug in the timer function, which is a part of the standard Clock application.
When the requested time is up, the timer makes the expected signal and displays the dialog window with "Dismiss" button. I hit "Dismiss" and it shuts up, as it should. However, if I leave the phone alone after that, after a while the timer signal will activate again for no apparent reason.
I haven't tested it thoroughly yet, so I don't know all details that affect the reproducibility the problem. The steps that reliably reproduce the issue are as follows:
1) Start the countdown and let the phone go to sleep (lock itself)
2) When timer sets off, the phone wakes up and displays the "Dismiss" dialog on top of the lockscreen. Hit the "Dismiss" button on the lockscreen, but don't unlock the phone. Just let it go to sleep again.
3) After a while the timer will set off again for no reason
It appears that the spurious activation of the timer signal is tied to some specific time period measured from the moment the countdown was originally started. In my case it is about 50 minutes. If I set the timer to 40 minutes, dismiss it when it signals, then I'll get another spurious timer signal about 10 minutes later. If I set the timer to 5 minutes, dismiss it when it signals, then I'll get another spurious timer signal about 45 minutes later.
If after the first signal I unlock the phone and go to the timer settings (just to check that the timer is not running again somehow), the second timer signal never occurs.
I'm wondering whether this is Android bug or HTC Sense bug, i.e. what are the chances it is fixed in Android 2.3...

[Q] Wake Lock in Samsung Galaxy Tab

Hi all, I am developing an app in which i need to send and receive packets in background. But I've discovered that when screen shut off also cpu and networking is disabled. So I've found on Android Developers that I should use wake lock and wifi lock to let the cpu works altought if the screen went off. This solution works for other devices such LG Optimus One but not for Samsung Galaxy Tab. With this device when screen shut off I can't receive no more packets (UDP) and magically when I press power button for re enabling screen, I restart to receive packets.
In my code I call:
powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_W AKE_LOCK, "TAG");
then
wakeLock.acquire();
I think that is a Samsung bug but I'm not sure of this, and if someone can give me some hint i would really appreciate.
P.S. I need some programming help... I already know that if I modify some manual setting to avoid shutting down the screen, this will work. But I'm developing an app and i need code!!

Lockscreen display turning off by display timeout (not by lockscreen timeout)

Aplications may cause that problem? Restarting phone or removing battery doesnt solve that problem. I have set 2min display timeout and immidiate lockscreen timeout but while phone is locked it turns off display after 2 min.
So all works like it's supposed to!
Not an issue nothing to see here move along.

Categories

Resources