eclipse - In Android How to Restart App On Click Application "onGoing" Notification. if App is open or not -


in android how restart app on click application "ongoing" notification. if app open or not.

like when click on ongoing notification "connected media device"

you can define actions want happen when interacting notification adding pendingintent.

in following example pendingintent created launch (current) activity. intent added notification in content section. once notification shown, when click content section, intent fired , app gets started or brought top.

private static final int notification_id = 1; ... notificationmanager nm = (notificationmanager) getsystemservice(notification_service); notificationcompat.builder nb = new notificationcompat.builder(this);  pendingintent pendingintent = pendingintent.getactivity(this, 0,         new intent(this, mainactivity.class)                 .setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top),         0); nb.setsmallicon(r.drawable.abc_ic_ab_back_mtrl_am_alpha)      .setcategory(notificationcompat.category_status)      .setvisibility(notificationcompat.visibility_public)     .setcontenttitle(gettext(r.string.app_name))     .setcontenttext("click launch!")     .setwhen(system.currenttimemillis())     .setcontentintent(pendingintent) // here "onclick" intent added     .setongoing(false);  nm.notify(notification_id, nb.build()); 

in case notification dismissable. if set .setongoing(true) need remove calling .cancel(notification_id) on instance of notificationmanager.

see introduction on how build notification.


Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -