diff --git a/e2e/modal-navigation/app/android-back-button/android-back-button-page.ts b/e2e/modal-navigation/app/android-back-button/android-back-button-page.ts
new file mode 100644
index 000000000..dcf20cde3
--- /dev/null
+++ b/e2e/modal-navigation/app/android-back-button/android-back-button-page.ts
@@ -0,0 +1,32 @@
+import { android as androidApp, AndroidActivityBackPressedEventData } from "tns-core-modules/application";
+import { fromObject, Observable } from "tns-core-modules/data/observable"
+
+let context: Observable;
+function activityBackPressedCallback(args: AndroidActivityBackPressedEventData) {
+ if (context && context.get("shouldCancel")) {
+ context.set("shouldCancel", false);
+ context.set("message", "Back-pressed canceled!");
+ args.cancel = true;
+ }
+}
+export function onLoaded(args) {
+ console.log("back-button modal test loaded");
+ context = fromObject({
+ message: "First back-press will be canceled",
+ shouldCancel: true
+ });
+
+ args.object.bindingContext = context;
+
+ if (androidApp) {
+ androidApp.on("activityBackPressed", activityBackPressedCallback);
+ }
+}
+
+export function onUnloaded(args) {
+ console.log("back-button modal test unloaded");
+
+ if (androidApp) {
+ androidApp.off("activityBackPressed", activityBackPressedCallback);
+ }
+}
diff --git a/e2e/modal-navigation/app/android-back-button/android-back-button-page.xml b/e2e/modal-navigation/app/android-back-button/android-back-button-page.xml
new file mode 100644
index 000000000..3da48a7a9
--- /dev/null
+++ b/e2e/modal-navigation/app/android-back-button/android-back-button-page.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/e2e/modal-navigation/app/home/home-page.ts b/e2e/modal-navigation/app/home/home-page.ts
index 6537e5b79..54cb458fa 100644
--- a/e2e/modal-navigation/app/home/home-page.ts
+++ b/e2e/modal-navigation/app/home/home-page.ts
@@ -57,6 +57,15 @@ export function onModalLayout(args: EventData) {
false);
}
+export function onAndroidBackEvents(args: EventData) {
+ const view = args.object as View;
+ view.showModal(
+ "android-back-button/android-back-button-page",
+ null,
+ () => console.log("android-back-button modal page layout closed"),
+ true, true, true);
+}
+
export function onModalTabView(args: EventData) {
const fullscreen = false;
const animated = false;
diff --git a/e2e/modal-navigation/app/home/home-page.xml b/e2e/modal-navigation/app/home/home-page.xml
index 4abbc0488..9a85f1f33 100644
--- a/e2e/modal-navigation/app/home/home-page.xml
+++ b/e2e/modal-navigation/app/home/home-page.xml
@@ -19,5 +19,6 @@
+
diff --git a/tns-core-modules/ui/core/view/view.android.ts b/tns-core-modules/ui/core/view/view.android.ts
index 77dee005d..c32b0342f 100644
--- a/tns-core-modules/ui/core/view/view.android.ts
+++ b/tns-core-modules/ui/core/view/view.android.ts
@@ -1,7 +1,6 @@
// Definitions.
import { Point, CustomLayoutView as CustomLayoutViewDefinition, dip } from ".";
import { GestureTypes, GestureEventData } from "../../gestures";
-import { AndroidActivityBackPressedEventData } from "../../../application";
// Types.
import {
ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty,
@@ -22,6 +21,7 @@ import {
import { Background, ad as androidBackground } from "../../styling/background";
import { profile } from "../../../profiling";
import { topmost } from "../../frame/frame-stack";
+import { AndroidActivityBackPressedEventData, android as androidApp } from "../../../application";
export * from "./view-common";
@@ -107,6 +107,13 @@ function initializeDialogFragment() {
activity: view._context,
cancel: false,
};
+
+ // Fist fire application.android global event
+ androidApp.notify(args);
+ if (args.cancel) {
+ return;
+ }
+
view.notify(args);
if (!args.cancel && !view.onBackPressed()) {