Open NickIliev opened 5 years ago
I am getting this issue. Anyone has a solution?
Hello, have the same problem when triggering the back-button on specific pages. (dont understand the original example with triggering twice and reopen. For me, just the "normal" workflow is breaking it.
application.android.on(application.AndroidApplication.activityBackPressedEvent, (args: any) => {
this.ngZone.run(() => {
args.cancel = true;
if (this.router.canGoBack()) {
this.router.back();
}
}
});
I also have this problem!
facing the same problem.
I have same issue on IOS :'(
I’ve same this issue. let me know if this is resolve. thanks everyone
When you use the back button twice you're not completely exiting the app, but the UI is destroyed (including angular). What's happening is:
android.on(function_on_instance1)
function_on_instance1
android.on(function_on_instance2)
function_on_instance1
then function_on_instance2
Solution:
ngOnInit() {
application.android.on(application.AndroidApplication.activityBackPressedEvent, handleBackButton, this);
}
ngOnDestroy() {
application.android.off(application.AndroidApplication.activityBackPressedEvent, handleBackButton, this);
}
handleBackButton(args: any) {
this.ngZone.run(() => {
args.cancel = true;
if (this.router.canGoBack()) {
this.router.back();
}
}
}
When you use the back button twice you're not completely exiting the app, but the UI is destroyed (including angular). What's happening is:
- You call
android.on(function_on_instance1)
- You press back button to exit
- it calls
function_on_instance1
- it exits and destroys the angular instance
- open app, new angular instance
- You call
android.on(function_on_instance2)
- You press back button to exit
- it calls
function_on_instance1
thenfunction_on_instance2
Solution:
ngOnInit() { application.android.on(application.AndroidApplication.activityBackPressedEvent, handleBackButton, this); } ngOnDestroy() { application.android.off(application.AndroidApplication.activityBackPressedEvent, handleBackButton, this); } handleBackButton(args: any) { this.ngZone.run(() => { args.cancel = true; if (this.router.canGoBack()) { this.router.back(); } } }
Thanks for this @edusperoni !
@bastianjoel commented on Thu Jul 04 2019
Environment
Describe the bug Calling canGoBack() of RouterExtensions causes the following exception when using inside back button listener.
To Reproduce General:
Add a android back button listener and define property
tries
Expected behavior
Sample project https://play.nativescript.org/?template=play-ng&id=AO3iYR&v=343
Additional context