Toast after seconds set by timepicker when screen off android -
i can detect when screen turns off in way:
intentfilter intentfilter = new intentfilter(intent.action_screen_on); intentfilter.addaction(intent.action_screen_off); registerreceiver(new broadcastreceiver() { @override public void onreceive(context context, intent intent) { if (intent.getaction().equals(intent.action_screen_off)) { toast.maketext(mainactivity.this, "screen off", toast.length_short).show(); } else if (intent.getaction().equals(intent.action_screen_on)) { toast.maketext(mainactivity.this, "screen on", toast.length_short).show(); } } }, intentfilter);
i need same thing, toast
have appears after seconds can set through timepicker
. every time screen turns off, if set 10 seconds, after 10 seconds toast. how can it? need service? manually can this:
new handler().postdelayed(new runnable() { @override public void run() { // here code } }, 30 * 1000);
but if set seconds time picker better. thanks
doing timer fine, toast on powered off screen... understand never appear, right?
if want apply delay, prefer executors.newsinglethreadscheduledexecutor() on handler.postdelayed().
should work. want user input delay.
just use timepicker dialog, , set delay in callback.
Comments
Post a Comment