Prevent the back button from closing the application


#1

I am using Nativescript with Angular on Android. I have read that the application closes if I press the back button when the navigation stack is empty. However, I have done some experiments and what I see is that the application goes to background (ngOnDestroy is not called), but there doesn’t seem to be any way for me to resume it. If I click on the app icon, a new instance of the application is launched. I don’t want multiple instances of my application. Is it possible to configure the back button to just “minimize” the application (like when I press the home button)? Or, how can I resume the one that is running on the background?

Btw, I have also tried with:

android:alwaysRetainTaskState="true"
android:launchMode="singleTask"

but the back button still “half-closes” my application.

Is this the expected behavior? a bug? a matter of configuration?

Any help is appreciated. Let me know if I should include a sample code.

Thanks!

Lucía


#2

Ok, treating the back event as a home event solves the problem:
http://stackoverflow.com/questions/28162815/i-need-to-minimize-the-android-application-on-back-button-click

How to do it in Nativescript:
http://www.nativescriptsnacks.com/snippets/2016/11/03/back-button.html