android - How to prevent intent opening an activity automatically upon receiving push notification -


i having strange issue whenever receive push notification in device activity gets opened automatically. don't want activity show automatically. want open activity manually when user clicks on notification.

here method executed upon receiving push notification:-

@override     protected void onmessage(context context, intent intent) {              string message = intent.getextras().getstring("message");              // notifies user             generatesupportnotification(context, message);      } 

this method called when push notification receives

private void generatesupportnotification(context context, string message) {          string classstring = "com.pkgname.mainactivity"         intent notificationintent = new intent();         notificationintent.setclassname(context, classstring);         // set intent not start new activity         notificationintent.setflags(intent.flag_activity_clear_top                 | intent.flag_activity_single_top);         pendingintent resultpendingintent = pendingintent.getactivity(context,                 0, notificationintent, pendingintent.flag_update_current);          final boolean iskitkat = build.version.sdk_int <= build.version_codes.kitkat;          if (iskitkat) {             notificationcompat.builder notification = new notificationcompat.builder(                     getapplicationcontext())                     .setsmallicon(r.drawable.ic_launcher)                     .setcontenttitle("reshotel")                     // .setcontenttext("welcome!!!")                     .setcontentintent(resultpendingintent)                     .setstyle(                             new notificationcompat.bigtextstyle()                                     .bigtext(message))                     .setfullscreenintent(resultpendingintent, true)                     .setautocancel(false);             boolean isvibrate = new devicepreferences().getboolean(context,                     constants.vibrate, true);             boolean issound = new devicepreferences().getboolean(context,                     constants.sound, true);             if (isvibrate && issound) {                 notification.setdefaults(notification.default_sound                         | notification.default_vibrate);             } else if (isvibrate && !issound) {                 notification.setdefaults(notification.default_vibrate);             } else if (!isvibrate && issound) {                 notification.setdefaults(notification.default_vibrate);             }              notificationmanager manager = (notificationmanager) getsystemservice(context.notification_service);             manager.notify(0, notification.build());         } else {             notificationcompat.builder notification = new notificationcompat.builder(                     getapplicationcontext())                     .setcategory(notificationcompat.category_message)                     .setvisibility(notificationcompat.visibility_public)                     .setsmallicon(r.drawable.ic_launcher)                     .setcontenttitle("reshotel")                      .setcontenttext(message)                     .setcontentintent(resultpendingintent)                     .setstyle(                             new notificationcompat.bigtextstyle()                                     .bigtext(message))                     .setfullscreenintent(resultpendingintent, true)                     .setautocancel(false);              // notification.setautocancel(true);             boolean isvibrate = new devicepreferences().getboolean(context,                     constants.vibrate, true);             boolean issound = new devicepreferences().getboolean(context,                     constants.sound, true);             if (isvibrate && issound) {                 notification.setdefaults(notification.default_sound                         | notification.default_vibrate);             } else if (isvibrate && !issound) {                 notification.setdefaults(notification.default_vibrate);             } else if (!isvibrate && issound) {                 notification.setdefaults(notification.default_vibrate);             }              notificationmanager manager = (notificationmanager) getsystemservice(context.notification_service);             manager.notify(1, notification.build());         }      } 

use code generate notification

private static void generatenotification(context context ,string name,string number) {   int icon = r.drawable.ic_launcher;     long when = system.currenttimemillis();     intent notificationintent = null;     @suppresswarnings("deprecation")     notification notification = new notification(icon, "", when);     notificationmanager notificationmanager = (notificationmanager)context.getsystemservice(context.notification_service);      notificationintent = new intent(intent.action_dial);     notificationintent.setflags(intent.flag_activity_clear_top);     string p = "tel:" + number.trim();     notificationintent.setdata(uri.parse(p));     pendingintent intent = pendingintent.getactivity(context, 0, notificationintent, pendingintent.flag_update_current);      notification.setlatesteventinfo(context, "uposi", "callback reminder "+name, intent);    // notification.flags |= notification.flag_auto_cancel;       notification.flags |= notification.flag_only_alert_once | notification.flag_auto_cancel;     notification.sound = uri.parse(contentresolver.scheme_android_resource + "://" + context.getpackagename() + "/raw/notification");     notification.defaults |= notification.default_vibrate;              notificationmanager.notify(generateuniqueid(), notification); 

Comments