Не удается получить OnNewIntent () для запуска - PullRequest
1 голос
/ 30 апреля 2020

так что я перебрал более 7 вопросов о стековом потоке с решениями для решения этой проблемы onNewIntent (), но даже после всего, что я не могу заставить его работать.

Активность, которую я хочу вызвать onNewIntent ():

<activity android:name=".View.Activities.ViewStatus"
        android:launchMode="singleTop"/>
    <activity

В действии ViewStatus:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    String author_ = intent.getStringExtra("author");
    String postedTo_ = intent.getStringExtra("postedTo");
    String key_ = intent.getStringExtra("key");

    Log.d(TAG, "onNewIntent: \nauthor: "+author_+"\npostedTo: "+postedTo_+"\nkey: "+key_);

}

Я запускаю уведомление, но при нажатии на уведомление моё onNewIntent () не срабатывает:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                                        //https://stackoverflow.com/questions/44443690/notificationcompat-with-api-26
                                        builder = new Notification.Builder(getApplicationContext(), CHANNEL_ID)
                                                .setGroupSummary(true)
                                                //.setOnlyAlertOnce(true)
                                                .setGroup(String.valueOf(notifId))
                                                .setSmallIcon(R.drawable.logo_notification)
                                                .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
                                                .setContentTitle(fromUser.getFirstname() + " " + fromUser.getLastname() + " commented:")
                                                .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS)
                                                .setSound(soundUri)
                                                .setTimeoutAfter(40000) //40s
                                                .setOnlyAlertOnce(true)
                                                .setContentText(statusUpdate.getStatus())
                                                .setStyle(new Notification.BigTextStyle() //https://developer.android.com/training/notify-user/expanded
                                                        .bigText(statusUpdate.getStatus()));
                                    } else {
                                        builder = new Notification.Builder(getApplicationContext())
                                                .setGroupSummary(true)
                                                //.setOnlyAlertOnce(true)
                                                .setGroup(String.valueOf(notifId))
                                                .setSmallIcon(R.drawable.logo_notification)
                                                .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
                                                .setContentTitle(fromUser.getFirstname() + " " + fromUser.getLastname() + " commented:")
                                                .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS)
                                                .setSound(soundUri)
                                                .setAutoCancel(true)
                                                .setOnlyAlertOnce(true)
                                                .setPriority(Notification.PRIORITY_MAX)
                                                .setContentText(statusUpdate.getStatus())
                                                .setStyle(new Notification.BigTextStyle() //https://developer.android.com/training/notify-user/expanded
                                                        .bigText(statusUpdate.getStatus()));
                                    }

                                }

                                Intent intent = new Intent(ForegroundService.this, ViewStatus.class);
                                intent.putExtra("author", newNotification.getAuthor());
                                intent.putExtra("postedTo", newNotification.getPostedTo());
                                intent.putExtra("key", newNotification.getMessage());
                                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                                PendingIntent contentIntent = PendingIntent.getActivity(ForegroundService.this, notifId, intent,PendingIntent.FLAG_UPDATE_CURRENT);
                                builder.setContentIntent(contentIntent);
                                Notification notification = builder.build();
                                notification.flags |= Notification.FLAG_AUTO_CANCEL;
                                notification.defaults |= Notification.DEFAULT_SOUND;
                                notification.icon |= Notification.BADGE_ICON_LARGE;
                                manager.notify(notifId, notification);

Есть что-то, что я пропускаю?

1 Ответ

0 голосов
/ 30 апреля 2020

Изменение с singleTop на singleTask спасло ситуацию согласно этому сообщению: Android режим запуска "top top" и метод onNewIntent

...