2016-05-21 3 views
0

Открываем мероприятие при нажатии уведомления. Но если эта деятельность уже открыта, я хочу снова открыть эту деятельность. От reopen Я имею в виду это; закрыть эту активность и снова открыть ее, чтобы отображать обновленные данные. Для делать это я добавляю эту строку кода намерению уведомления:как повторно открыть мероприятие при нажатии на ссылку/прослушивание

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 

Но проблема в том, что, когда я нажимаю/уведомление водопроводную, все приложение закрыто вместо отделки только эту деятельность. Так что, пожалуйста, помогите.

+0

Вы можете повторно использовать ту же самую деятельность, определяя андроид: launchmode = «SingleTop» или «SingleInstance» в теге манифеста файла, так что вы можете использовать существующий экземпляр, если он уже открыт –

ответ

1

вы можете проверить, если Activity уже открыт. Я сделал этот путь

public static boolean FLAG=false; 

в onCreate сделать его true

@Override 
protected void onCreate(Bundle savedInstanceState) { 
FLAG=true; 
. 
. 
} 

теперь вы можете проверить значение этой переменной в Notification классе.

boolean isOpen=YourActivty.FLAG; 
if(isOpen){ 
//just clear the notification with adding the notification's data in the activity if you are sending to any listview or so. 
//for adding the data to listview you need to make the `ArrayList`(i assume) and make a method in the adapter that will notify the adapter. 
}else{ 
//call the Activity 
} 
+0

это хорошо. но я хочу внести изменения после нажатия на уведомление –

+0

какие изменения вы хотите –

+0

Я хочу выделить элемент списка –

0

Используйте этот

  notificationManager = (NotificationManager) context 
       .getSystemService(Context.NOTIFICATION_SERVICE); 

     Intent notificationIntent = null; 
     notificationIntent = new Intent(context, SplashScreen.class); 

     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
       | Intent.FLAG_ACTIVITY_NEW_TASK 
       | Intent.FLAG_ACTIVITY_CLEAR_TASK); 

     PendingIntent intent = PendingIntent.getActivity(context, 0, 
       notificationIntent, 0); 
     RemoteViews notiview = new RemoteViews(getPackageName(), 
       R.layout.notification_layout); 
     final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
       context).setSmallIcon(small_icon) 
     // .setContentTitle(title) 
       .setAutoCancel(true) 
       // .setStyle(
       // new NotificationCompat.BigTextStyle().bigText(message)) 
       .setDefaults(
         Notification.DEFAULT_SOUND 
           | Notification.DEFAULT_VIBRATE) 
       // .setContentText(message).setNumber(noticount); 
       .setContent(notiview); 
     notiview.setTextViewText(R.id.noti_msgcount, "" + noticount); 
     notiview.setTextViewText(R.id.noti_msgtxt, msgOld); 

     mBuilder.setContentIntent(intent); 
Смежные вопросы