android - Doesn't call fragment from notification bar -


i calling fragment class notification bar click event. when click on notification bar can't open fragment class have called have checked 1 static boolean variable. still not working.

code notification:

private void generatenotification(context context, string message) {          int icon = r.drawable.kutch_smallpng;         long when = system.currenttimemillis();         notificationmanager notificationmanager = (notificationmanager) context                 .getsystemservice(context.notification_service);         // notification notification = new notification(icon, message, when);         notificationcompat.builder notificationbuilder = null;         string title = context.getstring(r.string.app_name);         int requestid = (int) system.currenttimemillis();          intent notificationintent = new intent(context, mainmenuactivity.class);         // set intent not start new activity          if (notificationintent != null) {             notificationintent.setaction("currentoffersfragment" + requestid);          }          notificationintent.setflags(intent.flag_activity_clear_top                 | intent.flag_activity_single_top);          pendingintent intent = pendingintent.getactivity(context, requestid,                 notificationintent, 0);         // notification.setlatesteventinfo(context, title, message, intent);         // notification.flags |= notification.flag_auto_cancel;         notificationbuilder = new notificationcompat.builder(                 getapplicationcontext()).setwhen(when).setcontenttext(message)                 .setcontenttitle(title).setsmallicon(icon).setautocancel(true)                 .setdefaults(notification.default_lights)                 .setcontentintent(intent);         uri defaultringtoneuri = ringtonemanager                 .getdefaulturi(ringtonemanager.type_notification);         notificationbuilder.setsound(defaultringtoneuri);         notificationbuilder.setdefaults(notification.default_vibrate);          notification notification = notificationbuilder.build();         notificationmanager.notify((int) when, notification);          log.v("my message is", message);         notificationclicked = true;      } 

now in mainmenuactivity's oncreate() method calling this.

  intent intent = getintent();          if (intent != null) {              log.e("is clicked", "true");              try {                 if (notificationclicked == true                         && intent.getaction().equals("currentoffersfragment")) {                     fragment fragment = new currentoffersfragment();                      // txtmaintitlebar.settext("current offers");                     fragmentmanager = getsupportfragmentmanager();                      fragmenttransaction ft = fragmentmanager.begintransaction();                     ft.add(r.id.container, fragment);                     fragmentstack.push(fragment);                     ft.commit();                  }             } catch (exception e) {                 // todo: handle exception              }              // }          } 

but here did not fulfill condition of notificationclicked == true && intent.getaction().equals("currentoffersfragment").

so please this. appropriate.

finally got answer. have changed

make static boolean variable in mainmenuactivity

public static boolean notificationclicked = false; 

and after make true in notification class

notificationclicked = true; 

and check in mainmenuactivity

 intent intent = getintent();          if (intent != null) {              try {                 if (notificationclicked == true) {                     fragment fragment = new currentoffersfragment();                      txtmaintitlebar.settext("current offers");                     fragmentmanager = getsupportfragmentmanager();                      fragmenttransaction ft = fragmentmanager.begintransaction();                     ft.add(r.id.container, fragment);                     fragmentstack.push(fragment);                     ft.commit();                  }             } catch (exception e) {                 // todo: handle exception              }              // }               } 

the problem here

 if (notificationintent != null) {         notificationintent.setaction("currentoffersfragment" + requestid);    } 

so have removed one. working charm.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -