android - Prevent multiple instances in webview activity -
i have webview activity, in it's url updated notification service. when notification clicked new activity created everytime load changed url. can prevented adding android:launchmode="singletask"
in manifiest.
if new activity created every time when notification clicked leads me change content perfectly. want avoid creating new activity(or maybe view created idk?) every time notification clicked. if add android:launchmode="singletask"
in manifest, gives me side-effect, i.e if notification arrived on existing opened webview activity not redirect changed url.
pending notification intent:
notificationmanager mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); if (ismessage) { intent intent = new intent(this, miscdisplay.class); intent.putextra("start_url", url); intent.setaction("notification_url_action"); pendingintent resultpendingintent = pendingintent.getactivity(getapplicationcontext(), 1, intent, pendingintent.flag_update_current); mbuilder.setcontentintent(resultpendingintent); mbuilder.extend(new wearableextender().addaction(message)); mbuilder.setongoing(false); mbuilder.setsmallicon(r.mipmap.ic_launcher); mbuilder.setonlyalertonce(true); notification note = mbuilder.build(); mnotificationmanager.notify(1, note); } else { mbuilder.setsmallicon(r.mipmap.ic_launcher); intent intent = new intent(this, miscdisplay.class); intent.putextra("start_url", url); intent.setaction("notification_url_action"); taskstackbuilder stackbuilder = taskstackbuilder.create(this); stackbuilder.addparentstack(miscdisplay.class); stackbuilder.addnextintent(intent); pendingintent resultpendingintent = pendingintent.getactivity(getapplicationcontext(), 0, intent, pendingintent.flag_update_current); mbuilder.setcontentintent(resultpendingintent); mbuilder.extend(new notificationcompat.wearableextender().addaction(action)); mbuilder.setongoing(false); notification note = mbuilder.build(); mnotificationmanager.notify(0, note);
what want?
i want avoid creating new activity each time when new notification clicked.
please help! thank you.
intent activityintent = new intent(context, mainactivity.class);activityintent.addflags(intent.flag_activity_new_task | intent.flag_activity_clear_top | intent.flag_activity_single_top); context.startactivity(activityintent);
use flags before calling activity solution two: in manifest:
<application android:allowbackup="true" android:label="@string/app_name" android:name=".al" public class al extends application { public static boolean isactivityrunnig=false; @override public void oncreate() { super.oncreate(); }
in activity:
@override protected void onresume() { super.onresume(); al.isactivityrunnig= true; } @override protected void onpause() { super.onpause(); al.isactivityrunnig= false; }
and when click on notification can check falg:
if(!al.isactivityrunnig) startactivity(new intent(context,youractivity.class));
Comments
Post a Comment