android - Notification intent activity -
i got issue regarding notification intent. have 2 activity (a & b). activity main activity of application. first activity user go through. activity b when user enter clicking on button @ activity a.
the thing when clicked on notification , direct me activity b. direct me activity onbackpressed. when close application , open through multi-tasking option, resume application @ activity b. wanted application start @ activity instead after closing it.
the order should
activity --> activity b.
notification onclick -> activity b (onbackpressed) -> activity --> close.
re-open app / open multi-tasking feature --> activity a
please let me know if there other information can provide proper understanding question.
gcm_intent.class
notification note = new notification(icon, msgtopic ,system.currenttimemillis()); intent i=new intent(this, activity_b.class); i.putextra("topicid", topicid); i.setflags(intent.flag_activity_clear_top| intent.flag_activity_single_top); pendingintent pi=pendingintent.getactivity(this, communitiesappconstant.notification_id, i, pendingintent.flag_cancel_current | pendingintent.flag_one_shot); note.setlatesteventinfo(this, topicname ,msginfo+message, pi); note.flags |= notification.flag_auto_cancel | notification.flag_show_lights; note.ledargb |= 0xff0000ff; note.ledoffms |= 1000; note.ledonms |= 300; mgr.notify(communitiesappconstant.notification_id, note); activity b.class
@override public void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); setcontentview(r.layout.activity_b); bundle bundle = getintent().getextras(); topicid = bundle.getstring("topicid"); } @override public void onbackpressed() { super.onbackpressed(); log.e(tag, "onbackpressed"); intent = new intent(activity_b.this, activity_a.class); i.addflags(intent.flag_activity_clear_top); startactivity(i); finish(); }
notification message can display user outside of application's normal ui.this perfect code use of notification.
notificationcompat.builder mbuilder = new notificationcompat.builder(this) .setsmallicon(r.drawable.notification_icon) .setcontenttitle("my notification") .setcontenttext("hello world!"); // creates explicit intent activity in app intent resultintent = new intent(this, resultactivity.class); // stack builder object contain artificial stack // started activity. // ensures navigating backward activity leads out of // application home screen. taskstackbuilder stackbuilder = taskstackbuilder.create(this); // adds stack intent (but not intent itself) stackbuilder.addparentstack(resultactivity.class); // adds intent starts activity top of stack stackbuilder.addnextintent(resultintent); pendingintent resultpendingintent = stackbuilder.getpendingintent( 0, pendingintent.flag_update_current ); mbuilder.setcontentintent(resultpendingintent); notificationmanager mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); // mid allows update notification later on. mnotificationmanager.notify(mid, mbuilder.build());
Comments
Post a Comment