-
-
Notifications
You must be signed in to change notification settings - Fork 241
ngOnDestroy not called on Android back button #923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The observed behaviour is by design and expected as documented here
|
@NickIliev thank you for your reply. I've read the documentation you've send but it isn't completely clear to me how it describes the Android back button behaviour when there isn't really a component to go back to. When you click back you go the the android home screen. |
@dennis-montana perhaps, instead of the Angular life hooks, you can use the NativeScript application events for this case (or directly the Android events). |
I think the solution to that is to handle the activity-destroyed application event and actually kill the angular application when the event is fired. This should call the |
I solved this in our app by directly using the Android application event to call ngOnDestroy. android.on(AndroidApplication.activityDestroyedEvent, (args: AndroidActivityEventData) => {
if (args.activity.toString().startsWith('com.tns.NativeScriptActivity')) {
this.ngOnDestroy();
}
}); |
Hi @dennis-montana , |
@hdrdiab you can place this within your |
For now i've placed it inside the |
Hi, |
Status on this issue? |
@nuvoPoint We've run into it in our application. Steps to reproduce:
Now if you run |
I wrote an article about this. I solved it in generic way with the decorator. |
Uh oh!
There was an error while loading. Please reload this page.
We ran into an issue with ngOnDestroy not being called when we use the Android back button.
I've provided a sample application:
https://github.com/dennis-montana/back-button-issue
If you run the app on Android and click the back button you can see that ngOnDestroy isn't called while the native activityDestroyedEvent from Android is being called.
The app is still running in a sleeping state so everything created in ngOnInit is being created again every time a user uses the back button.
If you run the demo app you can see the following output:
As you can see the calls are being stacked.
The text was updated successfully, but these errors were encountered: