android - Send notification with delay -
i know if possible send notification in android delay. want notification message few seconds (i.e. 5 seconds) later received. nofication should created in normal way:
intent intent = new intent(this, myactivity.class); pendingintent pintent = pendingintent.getactivity(this, 0, intent, 0); notification n = new notification.builder(this) .setcontenttitle("title") .setcontenttext("text") .setsmallicon(r.drawable.icon) .setcontentintent(pintent) .setautocancel(true) .addaction(r.drawable.icon, "open", pintent).build(); i want avoid approach call thread.sleep(5000) before sending notification, because blocks app.
new handler(looper.getmainlooper()).postdelayed(new runnable() { @override public void run() { // code } }, 5000); this run code on main thread after 5 seconds. if running on current thread ok can remove looper.getmainlooper().
Comments
Post a Comment