android - How do I update Activity with intents passed via Notification -
i have created custom notification, when pause activity home button , notification arrives, press notification , creates new activity , doesnt resume previews activity , when press button goes previews 1 same window. have tried singletop, singletask, singleintent, works doesnt update activity when message enters, previews activity in pause. how can fix it?
if there no solution though in resuming activity or destroy paused activity or maybe restart activity, there way this?
public void customnotification(string strtext) { // using remoteviews bind custom layouts notification remoteviews remoteviews = new remoteviews(getpackagename(), r.layout.customnotification); // set notification title string strtitle = getstring(r.string.customnotificationtitle); // open notificationview class on notification click intent intent = new intent(this, notificationview.class); // send data notificationview class intent.putextra("title", strtitle); intent.putextra("text", strtext); intent.putextra("string t", ""); //intent.putextra("integer c", 0); // open notificationview.java activity pendingintent pintent = pendingintent.getactivity(this, 0, intent, pendingintent.flag_update_current); notificationcompat.builder builder = new notificationcompat.builder(this) // set icon .setsmallicon(r.drawable.ic_launcher) // set ticker message .setticker(getstring(r.string.customnotificationticker)) // dismiss notification .setautocancel(true) // set pendingintent notification .setcontentintent(pintent) // set remoteviews notification .setcontent(remoteviews); // locate , set image customnotificationtext.xml imageviews remoteviews.setimageviewresource(r.id.imagenotileft,r.drawable.ic_launcher); remoteviews.setimageviewresource(r.id.imagenotiright,r.mipmap.ic_action_chat); // locate , set text customnotificationtext.xml textviews remoteviews.settextviewtext(r.id.title,getstring(r.string.customnotificationtitle)); remoteviews.settextviewtext(r.id.text, strtext); // create notification manager notificationmanager notificationmanager = (notificationmanager) getsystemservice(notification_service); // build notification notification manager notificationmanager.notify(0, builder.build()); } logs:
04-29 01:29:10.453 29001-29001/com.example.example e/state﹕new activity 04-29 01:29:15.376 29501-29501/com.example.example d/activity﹕ activity.onpause(), edittexttapsensorlist size: 0 04-29 01:30:06.981 29501-29501/com.example.example e/state﹕ resuming when press notification:
04-29 01:33:09.654 33449-33530/com.example.example e/state﹕new activity i appreciate answer, thanks!
edited
answer:
the answer add:
intent.setflags(intent.flag_activity_clear_top | intent.flag_activity_new_task); because when in same window , pressed home button, activity in paused, if notification arrived brought me window didnt updated messages needed create new intent , erase previous 1 in pause. code did job.
try in service code use notification :
private static final int notify_me_id = 1222; notificationmanager mnotificationmanager = (notificationmanager) .getsystemservice(context.notification_service); private void notifi(string message){ int requestid = (int) system.currenttimemillis(); intent intent = new intent(intent.action_main); //clear previous activities , create new 1 intent.setflags(intent.flag_activity_clear_top | intent.flag_activity_new_task); intent.setcomponent(new componentname("packagenameofyourapplication", "packagenameofyourapplication.notificationview")); pendingintent pintent = pendingintent.getactivity(this, 0, intent, pendingintent.flag_update_current); notification notif = new notification.builder(this) .setcontenttitle(getstring(r.string.notification_titel)).setcontenttext(message) .setsmallicon(r.drawable.ic_launcher).setautocancel(true) .setcontentintent(pintent).build(); notif.flags = notification.flag_no_clear; mnotificationmanager.notify(notify_me_id, notif); }
Comments
Post a Comment