Я пытаюсь открыть фрагмент, когда нажимаю уведомление в панели уведомлений.
Структура моей приложения: < /p>
Базовая активность с меню ящика NAV < /li>
и некоторый фрагмент, которые открываются из меню < /li>
< /ul>
Указанный фрагмент выглядит для открытия и загрузки, но не с помощью пользовательского интерфейса. < /p>
Код уведомления: < /p>
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this);
mBuilder.setContentTitle("Comanda Noua");
mBuilder.setContentText("S-a introdus o comanda noua");
mBuilder.setTicker("Comanda noua!");
mBuilder.setSmallIcon(R.drawable.calculator_icon);
mBuilder.setAutoCancel(true);//inchide notificare dupa ce s-a dat click pe ea
//creste numar notificare
mBuilder.setNumber(++numMessages);
// cream un intent
Intent resultIntent = new Intent(this, MainActivity.class);
//am setat actiune pentru a deschide fragmentul corespunzator notificartii la apasare
resultIntent.setAction("Action1");
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
mNotificationManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// notificationID allows you to update the notification later on.
mNotificationManager.notify(notificationID, mBuilder.build());
< /code>
Код, где я открываю фрагмент при нажатии уведомления: < /p>
Intent intent = getIntent();
try{
String action = intent.getAction();
// Log.d("action:",action);
if(action.equals("Action1")){
//Log.d("deschidem agenda:",action);
AgendaFragment fragment = new AgendaFragment();
FragmentTransaction transaction = getFragmentManager()
.beginTransaction();
transaction.replace(R.id.frame_container, fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.addToBackStack(null).commit();
}else{
Log.d("eroare", "Intent was null");
}
}catch(Exception e){
Log.e("eroare", "Problem consuming action from intent", e);
}
< /code>
Почему активность открывается, но фрагмент не? < /p>
Подробнее здесь: https://stackoverflow.com/questions/244 ... in-android
Откройте фрагмент, когда нажмите уведомление в Android ⇐ Android
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение