Мое приложение вылетает при нажатии кнопки «Назад» на Android, когда приложение открывается из сообщения-уведомления nativescript-plugin-firebase - PullRequest
1 голос
/ 26 июня 2019

Я работаю над приложением nativescript-angular, которое получает уведомления [nativescript-plugin-firebase].

Проект обновлен.В package.json содержатся следующие строки:
"tns-android": {
"version": "5.4.0"
},
"tns-core-modules": "~ 5.4.0 ",
" @ angular / core ":" ~ 8.0.0 "
" nativescript-plugin-firebase ":" ^ 9.0.1 "

Уведомления в порядке, но приложениевылетает при нажатии на уведомление, если:

  • приложение открыто (на переднем плане)
  • устройство закрыто
  • , затем нажмите на уведомление о блокировке экрана
  • приложение вылетает
  • и отображает:

    An uncaught Exception occurred on 'main' thread.
    java.lang.RuntimeException: Unable to destroy activity
    

Я столкнулся с той же ошибкой на эмуляторе Android и на устройствах с Android 7,8 и 9.

Ошибка экрана здесь

А вот код уведомления внутри src \ app \ app.component.ts:

ngOnInit(): void {

    /// *** Firebase Cloud Messaging ***
    firebase.addOnMessageReceivedCallback(
        (message) => {
            const that = this;  
            let contentId: string = "";

            if (message.foreground) {
                /** If the app is already open, show a dialog message. **/
                confirm({
                    title: message.title,
                    message: message.body,
                    okButtonText: "Open",
                    cancelButtonText: "Cancel"
                }).then(function (result) {
                    // result argument is boolean
                    if (result) {
                        if (message.data.contentId) {
                            contentId = message.data.contentId;

                            if (parseInt(contentId) > 0) {
                                that.routerExtensions.navigate(["/car-detail/" + contentId], { clearHistory: false });
                            }
                        }
                    }
                    // console.log("Dialog result: " + result);
                });
            }
            else {
                /** Else if the message arrived when the app is in the background, this code is executed when the user taps on the notification. **/
                if (message.data.contentId) {
                    contentId = message.data.contentId;

                    if (parseInt(contentId) > 0) {
                        this.routerExtensions.navigate(["/car-detail/" + contentId], { clearHistory: false });
                    }
                }
            }
        }
    )

    if (this.authenticationService.FirebaseToken == undefined || this.authenticationService.FirebaseToken == null) {
        firebase.init({
            // Optionally pass in properties for database, authentication and cloud messaging, see their respective docs.
            onPushTokenReceivedCallback: function (token: any) {
                console.log("Firebase push token: " + token);
            }
            , showNotificationsWhenInForeground: true
        }).then(
            () => {
                console.log("firebase.init done");
            },
            error => {
                console.log(`firebase.init error: ${error}`);
            }
        );

        firebase.getCurrentPushToken().then((token: string) => {
            // may be null if not known yet
            console.log(`Current push token: ${token}`);
            this.authenticationService.FirebaseToken = token;
        });
    }

    // *** / Firebase Cloud Messaging ***
}  
...