[
https://issues.apache.org/jira/browse/CB-10554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15260818#comment-15260818
]
ASF GitHub Bot commented on CB-10554:
-------------------------------------
GitHub user riknoll opened a pull request:
https://github.com/apache/cordova-plugin-media-capture/pull/60
CB-10554: Implementing plugin save/restore API for Android
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:
```javascript
function onDeviceReady() {
// pendingcaptureresult is fired if the capture call is successful
document.addEventListener('pendingcaptureresult', function(mediaFiles) {
// Do something with result
});
// pendingcaptureerror is fired if the capture call is unsuccessful
document.addEventListener('pendingcaptureerror', function(error) {
// Handle error case
});
}
document.addEventListener('deviceready', onDeviceReady);
```
Whereas using the resume event directly would require us to expose a helper
API on Android:
```javascript
function onDeviceReady() {
document.addEventListener(resume, function(event) {
if(event.pendingResult && event.pendingResult.pluginServiceName ===
"Capture") {
if(event.pendingResult.pluginStatus === "OK") {
var rawMediaFiles = event.pendingResult.result;
// Here, we would need to expose some weird helper function
to deal with the native result
var mediaFiles = capture.wrapMediaFiles(mediaFiles);
// Do something with result
} else {
var error = event.pendingResult.result;
// Handle the error case
}
}
});
}
document.addEventListener('deviceready', onDeviceReady);
```
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.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/MSOpenTech/cordova-plugin-media-capture
CB-10554
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/cordova-plugin-media-capture/pull/60.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #60
----
----
> Media Capture: Null reference in low memory conditions
> ------------------------------------------------------
>
> Key: CB-10554
> URL: https://issues.apache.org/jira/browse/CB-10554
> Project: Apache Cordova
> Issue Type: Bug
> Components: Plugin Media Capture
> Environment: android
> Reporter: Adam Duren
> Assignee: Richard B Knoll
> Priority: Critical
> Labels: PR, android, pendingPR, triaged
>
> I have been testing my app in low memory conditions by setting the android
> developer setting of "Don't keep Activities" which simulates low memory
> conditions. Every time I use the capture plugin for video when returning from
> the capture activity the app crashes. It appears that the state is not saved
> and on resume there are now null references such as the callbackContext and
> results array. It is fixed by using the onRestoreStateForActivityResult and
> onSaveInstanceState methods.
> *Related Exception*
> {quote}
> 7 14:30:31.181 23432-24842/com.ionicframework.alto442183 E/AndroidRuntime:
> FATAL EXCEPTION: pool-3-thread-2
>
> Process: com.ionicframework.alto442183, PID: 23432
>
> java.lang.NullPointerException: Attempt to invoke virtual method 'void
> org.apache.cordova.CallbackContext.sendPluginResult(org.apache.cordova.PluginResult)'
> on a null object reference
>
> at org.apache.cordova.mediacapture.Capture$3.run(Capture.java:396)
>
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
>
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
>
> at java.lang.Thread.run(Thread.java:818)
> {quote}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]