CB-10554: Implementing plugin save/restore API for Android #60
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The purpose of this PR is to handle the case where the Webview gets destroyed in the background while a capture activity is in the foreground. #51 was invalidated by some updates that were recently made to the plugin to handle overlapping permission and activity requests.
Also worth noting is that I did something different than the usual resume event API for getting pending plugin callback results. Instead of returning the native result to the javascript directly, this plugin needs to first wrap the results returned by the native code in a
MediaFile
object for those results to be useful. For that reason, I altered the plugin to expose two document events on Android that the user can subscribe to rather than the cordova-android generated resume event. These events directly return the wrapped result rather than the raw native one. It ends up looking like this:Whereas using the resume event directly would require us to expose a helper API on Android:
I think this makes the API a bit cleaner and also opens the way for plugins that do much more heavy javascript work before returning callback results. This hasn't really come up before because the other two core plugins that had this issue (camera and contacts) could just pass the native result directly to the javascript.
I'd appreciate some feedback on this API and if it seems okay I might update the Android plugin guide with an example so that other plugins can use this pattern.