You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by thehuijb <gi...@git.apache.org> on 2015/03/29 01:22:48 UTC
[GitHub] cordova-android pull request: solves CB-8768 issue where onActivit...
GitHub user thehuijb opened a pull request:
https://github.com/apache/cordova-android/pull/170
solves CB-8768 issue where onActivityResult gets called before onResume after MainActivity gets killed
if one of the plugins launches startActivityForResult and the Android OS decides to kill our MainActivity. what happens when the launched activity is closed.
the previous activity (our MainActivity is relaunched and onActivityResult is called, our mainActivity however has not yet had the time to load all onload=true plugins so therefore the savedInstanceState callBackService can not be called.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/thehuijb/cordova-android develop
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/cordova-android/pull/170.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 #170
----
commit 2a981bdb196abe556e40c08d2c5f5511b2b6e732
Author: Serge Huijben <s....@gmail.com>
Date: 2015-03-29T00:12:14Z
solve issue where onActivityResult gets called before onResume
if one of the plugins launches startActivityForResult and the Android OS decides to kill our MainActivity. what happens when the launched activity is closed.
the previous activity (our MainActivity is relaunched and onActivityResult is called, our mainActivity however has not yet had the time to load all onload=true plugins so therefore the savedInstanceState callBackService can not be called.
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: solves CB-8768 issue where onActivit...
Posted by thehuijb <gi...@git.apache.org>.
Github user thehuijb commented on a diff in the pull request:
https://github.com/apache/cordova-android/pull/170#discussion_r27392930
--- Diff: framework/src/org/apache/cordova/CordovaActivity.java ---
@@ -314,10 +318,52 @@ public void startActivityForResult(Intent intent, int requestCode, Bundle option
* @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
*/
@Override
- protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
+ protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
LOG.d(TAG, "Incoming Result. Request code = " + requestCode);
super.onActivityResult(requestCode, resultCode, intent);
- cordovaInterface.onActivityResult(requestCode, resultCode, intent);
+ // check if plugins are ready to receive the result
+ if (this.pluginsReady) {
+ cordovaInterface.onActivityResult(requestCode, resultCode, intent);
+ this.findCallbackTries = 0;
+ } else {
+ /**
+ * If the Android OS kills this activity when a plugin launches an a new activity
+ * the onActivityResult event fires before the onResume event
+ * so we have to wait for the plugins to be loaded again before we can hand the result to the correct plugin.
+ */
+ final ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
--- End diff --
thanks for having a look and commenting.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: solves CB-8768 issue where onActivit...
Posted by agrieve <gi...@git.apache.org>.
Github user agrieve commented on a diff in the pull request:
https://github.com/apache/cordova-android/pull/170#discussion_r27391907
--- Diff: framework/src/org/apache/cordova/CordovaActivity.java ---
@@ -314,10 +318,52 @@ public void startActivityForResult(Intent intent, int requestCode, Bundle option
* @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
*/
@Override
- protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
+ protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
LOG.d(TAG, "Incoming Result. Request code = " + requestCode);
super.onActivityResult(requestCode, resultCode, intent);
- cordovaInterface.onActivityResult(requestCode, resultCode, intent);
+ // check if plugins are ready to receive the result
+ if (this.pluginsReady) {
+ cordovaInterface.onActivityResult(requestCode, resultCode, intent);
+ this.findCallbackTries = 0;
+ } else {
+ /**
+ * If the Android OS kills this activity when a plugin launches an a new activity
+ * the onActivityResult event fires before the onResume event
+ * so we have to wait for the plugins to be loaded again before we can hand the result to the correct plugin.
+ */
+ final ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
--- End diff --
Using a separate thread to accomplish what you want here is a bit overcomplicated and as is has the unwanted side-effect that the callback will be called on a non-UI thread. We also don't want to wait for a resume event to fire this.
I'd suggest instead:
- Call `CordovaInterfaceImpl.onActivityResult()`, as before (probably just revert all changes to CordovaActivity).
- Have `onActivityResult` just store the result if no initialization has happened yet.
- Change `CordovaInterfaceImpl.setPluginManager(pluginManager)` to `onCordovaInit(pluginManager)`
- Have `onCordovaInit` dispatch any pending result to the pluginManager (plugins services should be registered by now).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: solves CB-8768 issue where onActivit...
Posted by thehuijb <gi...@git.apache.org>.
Github user thehuijb closed the pull request at:
https://github.com/apache/cordova-android/pull/170
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org