android - Notification disappear after activity finish -
i have activity named a
start broadcast receiver
. activity a
triggered notification disappear automatically when activity destroy(finish). want keep notification until user click or manually clear notification.
how activity start broadcast receiver
intent = new intent(context,a.class); i.addflags(intent.flag_activity_new_task | intent.flag_activity_brought_to_front); i.putextras(intent.getextras()); context.startactivity(i);
notification
intent notificationintent = new intent(); notificationintent.setclass(context,b.class); notificationintent.setaction(intent.action_main); notificationintent.addcategory(intent.category_launcher); notificationintent.setflags( intent.flag_activity_brought_to_front); pendingintent pendingintent = pendingintent.getactivity(context, 0, notificationintent, 0); notification notification = new notificationcompat.builder(context) .setsmallicon(r.drawable.notification_small) .setcontenttitle(status) .setticker(status) .setautocancel(false) .setcontenttext(message) .setdefaults(notification.default_sound) .setlargeicon( bitmap.createscaledbitmap(icon, 128, 128, false)) .setcontentintent(pendingintent) .build();
manifest options
<activity android:name="com.example.activity.a" android:screenorientation="portrait" android:launchmode="singletask" android:taskaffinity="" android:excludefromrecents="true"/>
note: tried singleinstance no luck.
edit(fixed)
i made silly mistake. called clearall() instead of cancel specific notification in ondestroy() function.
i think cancelling notification in app when activity destroyed.
Comments
Post a Comment