I have had similar issues with back button before. In my app I have a login page where the user submits their phone number and then they are taken to a page where they enter the
You must use clearHistory
only if you don't want use to go back to Login back upon pressing back button.
When you press back button and there are no Pages in back stack, application will terminate. It will still appear in recent application but unlike iOS tapping on the recent application will restart it unless it was paused but another activity / home button.
You may override back button to pause application instead of terminating it.
import { isAndroid } from "@nativescript/core/platform";
import * as application from "@nativescript/core/application";
import { Frame } from "@nativescript/core/ui/frame";
if (isAndroid) {
application.android.on(application.AndroidApplication.activityBackPressedEvent, function (args) {
const frame = Frame.topmost();
if (frame && !frame.canGoBack()) {
args.cancel = true;
var startMain = new android.content.Intent(
android.content.Intent.ACTION_MAIN
);
startMain.addCategory(android.content.Intent.CATEGORY_HOME);
startMain.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
application.android.foregroundActivity.startActivity(startMain);
}
});
}
Playground Sample