Android turn on the screen -
i making application activity launch scheduled alarmmanager. appear if screen turned off , device locked.
to achive set window flags
final window win = getwindow(); win.addflags(windowmanager.layoutparams.flag_show_when_locked | windowmanager.layoutparams.flag_dismiss_keyguard); win.addflags(windowmanager.layoutparams.flag_keep_screen_on | windowmanager.layoutparams.flag_turn_screen_on | windowmanager.layoutparams.flag_allow_lock_while_screen_on);
and try obtain lock screen
if(_lock == null) { powermanager pm = (powermanager)app.getappcontext() .getsystemservice(context.power_service); _lock = pm.newwakelock( powermanager.full_wake_lock, "screenon"); _lock.acquire(); }
the _lock powermanager.wakelock released in onpause
protected void onpause() { if(_lock != null) { _lock.release(); } }
this code executed in oncreate , onrestart. works ok if activity not launched yet.
but if launched earlier screen not turned off.
- onrestart called first
- onresume called
- onpause called immediately
so activity not launched. question how turn on screen in such situation. (i using api 15).
just use code :
final window win = getwindow(); win.addflags(windowmanager.layoutparams.flag_show_when_locked | windowmanager.layoutparams.flag_dismiss_keyguard);
in oncreate() , remove other activity-cycle methods if not doing else this.
i don't think need more code use perform it.
Comments
Post a Comment