Skip to content

ngOnDestroy not called on Android back button #923

Closed
@dennis-montana

Description

@dennis-montana

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:

### Opened the app 1st time
JS: AppComponent ngOnInit

### Clicked back button
JS: Android activity destroyed

### Opened the app 2nd time
JS: handleResumeEvent
JS: AppComponent ngOnInit

### Clicked back button
JS: Android activity destroyed
JS: Android activity destroyed

### Opened the app 3rd time
JS: handleResumeEvent
JS: handleResumeEvent
JS: AppComponent ngOnInit

### Clicked back button
JS: Android activity destroyed
JS: Android activity destroyed
JS: Android activity destroyed

As you can see the calls are being stacked.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions