studio segundo plano notificaciones estado developer crear barra android android-fragments android-notifications android-pendingintent

segundo - Cómo abrir la página de fragmentos, cuando se presiona una notificación en Android



notificaciones en segundo plano android studio (3)

Necesitará comenzar su actividad base como siempre, pero agregue información adicional a la intención sobre qué fragmento de menú se abrirá. Aquí puede ver cómo se puede hacer: https://stackoverflow.com/a/8610916/1652236

Esto depende de la información adicional que recupere en el método ''onCreate ()'' de las actividades que utilizará para iniciar / cargar el fragmento.

Vea aquí, por ejemplo, cómo funcionan los fragmentos: http://www.tutorialspoint.com/android/android_fragments.htm http://developer.android.com/guide/components/fragments.html

La intención de lanzar este procedimiento será algo así como:

Intent notificationIntent = new Intent(getActivity(), Abc.class); notificationIntent.putExtra("menuFragment", "favoritesMenuItem");

y en tu actividad base:

@Override protected void onCreate(final Bundle savedInstanceState) { String menuFragment = getIntent().getStringExtra("menuFragment"); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); // If menuFragment is defined, then this activity was launched with a fragment selection if (menuFragment != null) { // Here we can decide what do to -- perhaps load other parameters from the intent extras such as IDs, etc if (menuFragment.equals("favoritesMenuItem")) { FavoritesFragment favoritesFragment = new FavoritesFragment(); fragmentTransaction.replace(android.R.id.content, favoritesFragment); } } else { // Activity was not launched with a menuFragment selected -- continue as if this activity was opened from a launcher (for example) StandardFragment standardFragment = new StandardFragment(); fragmentTransaction.replace(android.R.id.content, standardFragment); } }

Estoy intentando abrir un fragmento cuando presiono una notificación en la barra de notificaciones. La estructura de mi aplicación es:

  • Una actividad de base con un menú del cajón de navegación.
  • Algunos fragmentos que se abren desde el menú.

    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);

¿Puede alguien decirme cómo enlazar con la siguiente página de fragmentos (el código actual está en la clase que extiende el fragmento)


también debe agregar .commit (); y ft1.addToBackStack (null); de modo que no se superponga en la versión anterior y si no va a agregar este ft1.addToBackStack (nulo); en la parte posterior de su aplicación se cerrará, así que agregue esto de acuerdo con su funcionalidad

String menuFragment = getIntent().getStringExtra("menuFragment"); ft1 = getSupportFragmentManager().beginTransaction(); ft1.addToBackStack(null); ft1.replace(R.id.frame_container, favoritesFragment).commit();


notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP )

Como su intención estableció Flags: FLAG_ACTIVITY_SINGLE_TOP, "onCreate ()" no se llamará cuando se haya creado la actividad, debería recibir los parámetros en el método llamado "onNewIntent ()".