Skip to content

[Android] Routing stuck at blank screen after last back() call #417

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

Closed
corne-de-bruin opened this issue Aug 26, 2016 · 4 comments
Closed

Comments

@corne-de-bruin
Copy link

I've implemented a flow in our app where we show a blocking screen under certain circumstances. When the block is removed we call the back function on RouterExtensions, before we make the call we ask if it's possible to go back. If we can't go back we route the user to the first page of the app.

If the block screen is shown when the user was on the very first screen, he will get stuck on a blank page after we removed the block screen by calling the back function, even if we perform a specific route the user still gets stuck at the blank page.

I've created a small example application to demonstrate our workflow and the issue we encounter.
https://github.com/corne-de-bruin/Nativescript-angular-routing-issue-example

@vakrilov
Copy link
Contributor

vakrilov commented Aug 30, 2016

Hey @corne-de-bruin
Thanks for the project - I managed to run it and reproduce the problem.
One thing I noticed is that you were subscribing to the service multiple times. So, event the destroyed instances of block screen were causing navigations in some cases.

I have added an unsubscribe() calls in this PR and the app started work (at least I didn't manage to reproduce the original problem).

One other useful thing when debugging is subscribing to the router events. Which can help you get a better idea of what navigations are performed inside the app.

I hope that help you move on with the app.

@corne-de-bruin
Copy link
Author

corne-de-bruin commented Aug 30, 2016

Hey @vakrilov

Thanks for helping me out, indeed i totally forgot to call unsubscribe().
But still this didn't solve the problem for me.

I've merged you commit and that showed me the following issue:
Every time the app is closed by pressing the back button the ngOnInit is also fired when you resume the app but the ngOnDestroy is never called. This causes multiple resumeEvent handlers to be added.

If you pull the example app again you can see this behaviour also if you follow the flow below:
Open the app
Suspend the app
Open the app again
Press the back button
Resume the app

Now you will see that ngOnDestroy is never called and that the ngOnInit and the resumeEvent is called twice.

@dennis-montana
Copy link

dennis-montana commented Jul 10, 2017

I also have this issue in my app on Android.
When I click the physical back button, my components ngOnDestroy isn't called, when I reopen the app the ngOnInit is called again. This is causing resumeEvents being added again every time I reopen the app while the old resumeEvents are also still being fired.

I created a workaround by calling ngOnDestroy myself upon activityDestroyedEvent:

if (android) {
    android.on(AndroidApplication.activityDestroyedEvent, (args: AndroidActivityEventData) => {
        if (args.activity.toString().startsWith('com.tns.MyCustomActivity')) {
            this.ngOnDestroy();
        }
    });
}

@corne-de-bruin
Copy link
Author

corne-de-bruin commented Aug 24, 2017

The conclusion of this issue is the same as #923 and as of now duplicated

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

No branches or pull requests

3 participants