From 6fe6d25ca5d7f7f1b6ee24d9fe6f91cce1071784 Mon Sep 17 00:00:00 2001 From: Julien Le Bras Date: Fri, 7 Feb 2020 19:37:52 +0100 Subject: [PATCH] feat(android): Handle onDestroy lifecycle event in plugins (#2421) --- .../capacitor/src/main/java/com/getcapacitor/Bridge.java | 9 +++++++++ .../src/main/java/com/getcapacitor/BridgeActivity.java | 1 + .../capacitor/src/main/java/com/getcapacitor/Plugin.java | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java index e225110b86..e082ac5c96 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java @@ -846,6 +846,15 @@ public void onStop() { } } + /** + * Handle onDestroy lifecycle event and notify the plugins + */ + public void onDestroy() { + for (PluginHandle plugin : plugins.values()) { + plugin.getInstance().handleOnDestroy(); + } + } + public void onBackPressed() { PluginHandle appHandle = getPlugin("App"); if (appHandle != null) { diff --git a/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java b/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java index 423bcc048a..2df2882eaa 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java +++ b/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java @@ -177,6 +177,7 @@ public void onStop() { @Override public void onDestroy() { super.onDestroy(); + this.bridge.onDestroy(); if (this.mockWebView != null) { mockWebView.handleDestroy(); } diff --git a/android/capacitor/src/main/java/com/getcapacitor/Plugin.java b/android/capacitor/src/main/java/com/getcapacitor/Plugin.java index 3caeaed09d..94e325b8e8 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Plugin.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Plugin.java @@ -532,6 +532,11 @@ protected void handleOnPause() {} */ protected void handleOnStop() {} + /** + * Handle onDestroy + */ + protected void handleOnDestroy() {} + /** * Start a new Activity. *