Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handleOnDestroy for an Android plugin #2399

Closed
1 of 4 tasks
jlebras opened this issue Feb 4, 2020 · 3 comments · Fixed by #2421
Closed
1 of 4 tasks

Add handleOnDestroy for an Android plugin #2399

jlebras opened this issue Feb 4, 2020 · 3 comments · Fixed by #2421

Comments

@jlebras
Copy link
Contributor

jlebras commented Feb 4, 2020

Add handleOnDestroy for an Android plugin

Describe the Feature Request

The Android Plugin class has some android activity lifecycle methods which can be overwritten like handleOnResume, handleOnPause, etc...

Would it be possible to add a method handleOnDestroy to the Plugin which is called when the bridge activity's onDestroy is called ?

My use case is the need to clean up things when the app is killed (like programatically generated windows which persist even when the app is killed by the user...).

I'm aware that in some cases the onDestroy activity's method may not be called but I think it doesn't hurt to add it to the plugin Api.

Platform Support Requested

  • Android
  • iOS
  • Electron
  • Web

Related Code

For the meantime I edited the capacitor code to handle this (in the node_modules...).
Because those are simple modifications , I'm writting them here.

BridgeActivity.java

 @Override
 public void onDestroy() {
   super.onDestroy();
   this.bridge.onDestroy();
   if (this.mockWebView != null) {
     mockWebView.handleDestroy();
   }
   Log.d(LogUtils.getCoreTag(), "App destroyed");
 }

Bridge.java

/**
 * Handle onDestroy lifecycle event and notify the plugins
 */
 public void onDestroy() {
   for (PluginHandle plugin : plugins.values()) {
     plugin.getInstance().handleOnDestroy();
   }
 }

Plugin.java

/**
 * Handle onDestroy
 */
protected void handleOnDestroy() {}
@jcesarmobile
Copy link
Member

sounds good, maybe you can send a PR with those changes?

@jlebras
Copy link
Contributor Author

jlebras commented Feb 7, 2020

Yes sure, here is the PR #2421

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 12, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants