I am trying to open a fragment when I press a notification in the notification bar. My app structure is:
- a base activity with a nav drawer menu
some fragment that are opened from menu
b.setOnClickListener(new OnClickListener() { @SuppressWarnings({ "deprecation", "static-access" }) public void onClick(View v) { w_nm=(NotificationManager) getActivity().getSystemService(getActivity().NOTIFICATION_SERVICE); Notification notify=new Notification(R.drawable.notnificationlogo,waternoti,System.currentTimeMillis()); Intent notificationIntent = new Intent(getActivity(), Abc.class); PendingIntent pending=PendingIntent.getActivity(getActivity(), 0,notificationIntent, 0); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP ); notify.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; notify.setLatestEventInfo(getActivity(),waternoti,waternoti1, pending); w_nm.notify(0, notify);
Can anyone tell me how to link with next fragment page (the present code is in class that extends fragment)
You will need to start your base activity as usual, but add some extra info to the intent about what menu fragment will be opened. Here you can see how it can be done: https://stackoverflow.com/a/8610916/1652236
This depends on the extra information which you retrieve in the activities 'onCreate()' method in which you will use to start/load the fragment.
See here for example how work with fragments: http://www.tutorialspoint.com/android/android_fragments.htm http://developer.android.com/guide/components/fragments.html
It Intent to launch this procedure will be something like:
and in your base activity:
you should also add .commit(); and ft1.addToBackStack(null); so that it would not overlap on prevoius one and if you will not ad this ft1.addToBackStack(null); on back your app will exit so add this according to your functionality
As your intent set Flags: FLAG_ACTIVITY_SINGLE_TOP, "onCreate()" will not be called when the activity has been created, you should receive the params in the method called "onNewIntent()" instead.