java - How do i start activity when screen goes off? -


i have application doing work when devices screen goes off. have set broadcast receiver (intent.action_screen_off) , works fine. got record in logcat when devices screen goes off. far good.

my onreceive code action_screen_off uses code calculating stuff, , executes fine (when screen goes off). far good.

at end of onreceive code i'm starting new activity, oncreate of targeting activity not executing. (for example on htc desire 2.3.7 works fine. on htc wildfire s 2.3.5, xperia arc s 2.3.4 not execute, , on samsung galaxy ace 2.2.1 , depends. executing isn't). logcat shows onreceive executed till end activity not started. i'm using following code starting activity:

intent starth_activity = new intent(getapplicationcontext(), handleactivity.class);         starth_activity.addflags(intent.flag_activity_new_task);         starth_activity.addflags(intent.flag_activity_clear_top);         startactivity(starth_activity); 

the important things note:

  • i said on phones mentioned above doesn't work. not working immediately, should (when screen_off fires ). activity starts like.. 10-15 minutes after screen went off (which not acceptable)

  • when screen goes off , activity not start , if press power button on device immediatelyfires off target activity , app working normal. (again not acceptable. should fire automatically).

  • when device connected pc works should. activity starts immediatelyafter screen goes off.

after reading lot of stack overflow realized because maybe device goes sleep. that's why works normal if press power button, or wakes automatically after 10-15min because synchronizes or something. used wakelock.

//oncreate service powman = (powermanager) getsystemservice(power_service); wake = powman.newwakelock(powermanager.acquire_causes_wakeup, "tag");  //onreceive (screen goes off) wake.acquire(); 

but still without success. (am doing wrong?) wake lock acquired activity won't show on these devices.

basically i'm asking. how open usual activity when screen goes off? or @ least how turn screen on if activity won't start (remember, pressing on power button shows activity

i need now, because i'm getting frustrated this. thank help.

you should starting service instead of activity when screen goes off.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -