Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Opening push notification when app is suspended does duplicate angular services. #1533

Closed
000panther opened this issue Jan 15, 2020 · 2 comments

Comments

@000panther
Copy link
Contributor

000panther commented Jan 15, 2020

I am currently debugging duplicate services in an angular application. It seems as if they are caused by opening a push notification in a suspended android app. This seems to cause a partial reinitialization of the app and a new AppComponent as well as dependend services, which leads to problems with Routing and Navigation as well as state in the services.

I reproduced this behaviour in a demo app: https://github.com/000panther/nativescript-push-error/

In the following logs you can see that

Successfully installed on device with identifier 'FA81B1A02641'.
Restarting application on device FA81B1A02641...
Successfully synced application org.nativescript.pushdemo on device FA81B1A02641.
JS: HMR: Hot Module Replacement Enabled. Waiting for signal.
JS: construct firebaseService 1579085694744
JS: construct AppComponent
JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
JS: firebase init success
JS: got token1579085694744
JS: fIf-cdi5cQI:APA91bEgWIbxdoHo6JTaeiTZDWm0BvwdIIPf-9HLsowdhsPHfgF_f62t89ks0aS9NQs251PyRv-MXXNXDLXRKca7ZI1YvHyxhFSEg43OS2uH5by630wzbFcFH63BVqjdeqfMN9UCrzTE

Push Notification received - constructed again

JS: construct firebaseService 1579085748718
JS: construct AppComponent
JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
JS: firebase init error:  Firebase already initialized
JS: got message 1579085694744

Push notification is handled by old firebaseService - new service is not notified.

@000panther
Copy link
Contributor Author

I found a solution for the issue, but the problem is still present. It seems as if nativescript-firebase does not respect that the angular application is teared down and then bootstrapped again, but still tries to notifiy the old, teared down listener.

The way to resolve this is to attach a new listener when the application is bootstrapped again on resume, so the new nativescript-angular app will be notified. I updated my sample repository too.

What do you think, should we add this to the documentation?

@000panther
Copy link
Contributor Author

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant