You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by tony-- <gi...@git.apache.org> on 2015/04/08 21:03:16 UTC

[GitHub] cordova-android pull request: fix CB-8684 - support onStart/onStop...

GitHub user tony-- opened a pull request:

    https://github.com/apache/cordova-android/pull/173

    fix CB-8684 - support onStart/onStop lifecycle events in plugins for Android

    A couple notes about this PR.
    1. I feel pretty sure that CordovaActivity.shouldHandleStartOnAppViewInit is needed in order to reliably get an onStart event to interested plugins, but not sure about CordovaWebViewImpl.shouldCallOnStartDuringInit.  Don't want to add cruft, but would like these events to be reliable.
    2. I tried to add a reasonable test for this new feature, but I feel like there might be a more elegant approach?  I'm open to feedback and willing to modify the approach.  Also (per @agrieve suggestion), I set onload=true, but it seemed to be working without it (which seems a little weird, but I didn't want to delay this PR any further - will step through it later).

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/tony--/cordova-android CB-8684-clean-for-PR

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cordova-android/pull/173.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 #173
    
----
commit 683965c6e7759030352e8e45252ca6aa8b13bf1a
Author: Tony Homer <to...@intel.com>
Date:   2015-04-08T19:00:38Z

    CB-8684 support onStart/onStop lifecycle events in plugins for Android

----


---
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: fix CB-8684 - support onStart/onStop...

Posted by tony-- <gi...@git.apache.org>.
Github user tony-- commented on the pull request:

    https://github.com/apache/cordova-android/pull/173#issuecomment-91084720
  
    Whoops, forgot to remove LifeCyclePluginTestActivity from the manifest.  Thanks for catching it!


---
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: fix CB-8684 - support onStart/onStop...

Posted by tony-- <gi...@git.apache.org>.
Github user tony-- commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/173#discussion_r28009389
  
    --- Diff: test/src/org/apache/cordova/test/LifeCyclePluginTestActivity.java ---
    @@ -0,0 +1,44 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +package org.apache.cordova.test;
    +
    +import android.os.Bundle;
    +
    +import org.apache.cordova.ConfigXmlParser;
    +import org.apache.cordova.CordovaWebView;
    +
    +public class LifeCyclePluginTestActivity extends BaseTestCordovaActivity {
    --- End diff --
    
    Originally was trying to isolate the plugin loading so I wouldn't have to modify config.xml.  But now that I modified config.xml... I'll switch to MainTestActivity.


---
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: fix CB-8684 - support onStart/onStop...

Posted by tony-- <gi...@git.apache.org>.
Github user tony-- commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/173#discussion_r28010484
  
    --- Diff: test/androidTest/src/org/apache/cordova/test/CordovaPluginTest.java ---
    @@ -0,0 +1,126 @@
    +
    +package org.apache.cordova.test;
    +
    +/*
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + *
    + */
    +
    +import android.app.Activity;
    +import android.test.ActivityInstrumentationTestCase2;
    +
    +import org.apache.cordova.CordovaWebView;
    +
    +import java.io.IOException;
    +import java.lang.reflect.Method;
    +
    +public class CordovaPluginTest extends ActivityInstrumentationTestCase2<LifeCyclePluginTestActivity> {
    +
    +    public static String TAG = "CordovaPluginTest";
    +    protected LifeCyclePluginTestActivity testActivity;
    +    protected LifeCyclePlugin testPlugin;
    +    protected CordovaWebView cordovaWebView;
    +
    +    @SuppressWarnings("deprecation")
    +    public CordovaPluginTest() {
    +
    +        super("org.apache.cordova.test", LifeCyclePluginTestActivity.class);
    +    }
    +
    +    protected void setUp() throws Exception {
    +        super.setUp();
    +        testActivity = getActivity();
    +        cordovaWebView = testActivity.getCordovaWebView();
    +        testPlugin = (LifeCyclePlugin)cordovaWebView.getPluginManager().getPlugin("LifeCycle");
    +    }
    +
    +    private void invokeBlockingCallToLifeCycleEvent(final String lifeCycleEventName) {
    +        final CordovaPluginTest me = this;
    +        final Activity activity = this.testActivity;
    +        Runnable blockingRunnable = new Runnable() {
    +            public void run() {
    +                try {
    +                    Method method = me.getInstrumentation().getClass().getMethod(lifeCycleEventName, Activity.class);
    +                    method.invoke(me.getInstrumentation(), activity);
    +                } catch (Exception e) {
    +                    fail("An Exception occurred in invokeBlockingCallToLifeCycleEvent while invoking " + lifeCycleEventName);
    +                }
    +                me.getInstrumentation().callActivityOnStart(testActivity);
    +                synchronized(this)
    +                {
    +                    this.notify();
    +                }
    +            }
    +        };
    +        synchronized( blockingRunnable ) {
    +            testActivity.runOnUiThread(blockingRunnable);
    +            try {
    +                blockingRunnable.wait();
    --- End diff --
    
    I wasn't sure how to do it.  I looked over the docs and didn't see anything.  I'll read the doc for getInstrumentation().waitForIdleSync(); and switch.


---
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: fix CB-8684 - support onStart/onStop...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/cordova-android/pull/173


---
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: fix CB-8684 - support onStart/onStop...

Posted by svranch <gi...@git.apache.org>.
Github user svranch commented on the pull request:

    https://github.com/apache/cordova-android/pull/173#issuecomment-91933619
  
    unsubscribe
    
     
    
    Sandi Laufenberg 
    
    Cell  425.633.7888
    
    sandi@ladysword.biz  
    
    Portfolio:   www.LadySword.com <http://www.ladysword.com/> 
    
     
    
     
    
    From: tony-- [mailto:notifications@github.com] 
    Sent: Wednesday, April 8, 2015 5:18 PM
    To: apache/cordova-android
    Subject: Re: [cordova-android] fix CB-8684 - support onStart/onStop lifecycle events in plugins for Android (#173)
    
     
    
    I think I made changes that address all of your comments. Thanks for the feedback.
    
    —
    Reply to this email directly or view it on GitHub <https://github.com/apache/cordova-android/pull/173#issuecomment-91052668> .  <https://github.com/notifications/beacon/ACA3Yphq8F8E7myjIdF-0m9SWz18tFryks5n9aCGgaJpZM4D8rTh.gif> 
    



---
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: fix CB-8684 - support onStart/onStop...

Posted by tony-- <gi...@git.apache.org>.
Github user tony-- commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/173#discussion_r28009491
  
    --- Diff: test/androidTest/src/org/apache/cordova/test/CordovaPluginTest.java ---
    @@ -0,0 +1,126 @@
    +
    +package org.apache.cordova.test;
    +
    +/*
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + *
    + */
    +
    +import android.app.Activity;
    +import android.test.ActivityInstrumentationTestCase2;
    +
    +import org.apache.cordova.CordovaWebView;
    +
    +import java.io.IOException;
    +import java.lang.reflect.Method;
    +
    +public class CordovaPluginTest extends ActivityInstrumentationTestCase2<LifeCyclePluginTestActivity> {
    +
    +    public static String TAG = "CordovaPluginTest";
    +    protected LifeCyclePluginTestActivity testActivity;
    +    protected LifeCyclePlugin testPlugin;
    +    protected CordovaWebView cordovaWebView;
    +
    +    @SuppressWarnings("deprecation")
    +    public CordovaPluginTest() {
    +
    +        super("org.apache.cordova.test", LifeCyclePluginTestActivity.class);
    +    }
    +
    +    protected void setUp() throws Exception {
    +        super.setUp();
    +        testActivity = getActivity();
    +        cordovaWebView = testActivity.getCordovaWebView();
    +        testPlugin = (LifeCyclePlugin)cordovaWebView.getPluginManager().getPlugin("LifeCycle");
    +    }
    +
    +    private void invokeBlockingCallToLifeCycleEvent(final String lifeCycleEventName) {
    +        final CordovaPluginTest me = this;
    --- End diff --
    
    Ok.


---
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 issue #173: fix CB-8684 - support onStart/onStop lifecycle e...

Posted by rejhgadellaa <gi...@git.apache.org>.
Github user rejhgadellaa commented on the issue:

    https://github.com/apache/cordova-android/pull/173
  
    Hi, quick question: is this change just for plugins or can I hook into the onStart and onStop events in javascript as well? Because with Nougat apps need to be able to know if they stopped (not visible) or might be in split view but not focused (paused). In the latter case the app should probably still refresh its UI and such.


---
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: fix CB-8684 - support onStart/onStop...

Posted by tony-- <gi...@git.apache.org>.
Github user tony-- commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/173#discussion_r28019036
  
    --- Diff: framework/src/org/apache/cordova/CordovaActivity.java ---
    @@ -95,6 +95,9 @@ Licensed to the Apache Software Foundation (ASF) under one
         protected ArrayList<PluginEntry> pluginEntries;
         protected CordovaInterfaceImpl cordovaInterface;
     
    +    //flag for case when appView is null during onStart
    +    private boolean shouldHandleStartOnAppViewInit = false;
    --- End diff --
    
    My tests pass without it.  I'll remove it.  I'll also remove the similar flag from CordovaWebViewImpl.


---
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: fix CB-8684 - support onStart/onStop...

Posted by tony-- <gi...@git.apache.org>.
Github user tony-- commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/173#discussion_r28018642
  
    --- Diff: test/androidTest/src/org/apache/cordova/test/CordovaPluginTest.java ---
    @@ -0,0 +1,126 @@
    +
    +package org.apache.cordova.test;
    +
    +/*
    --- End diff --
    
    Whoops!  I used one of the other tests as a template - the package is above the copyright in all of them.  I'll move it regardless.


---
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: fix CB-8684 - support onStart/onStop...

Posted by tony-- <gi...@git.apache.org>.
Github user tony-- commented on the pull request:

    https://github.com/apache/cordova-android/pull/173#issuecomment-91052668
  
    I think I made changes that address all of your comments.  Thanks for the feedback.


---
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: fix CB-8684 - support onStart/onStop...

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/173#discussion_r28009343
  
    --- Diff: framework/src/org/apache/cordova/CordovaActivity.java ---
    @@ -95,6 +95,9 @@ Licensed to the Apache Software Foundation (ASF) under one
         protected ArrayList<PluginEntry> pluginEntries;
         protected CordovaInterfaceImpl cordovaInterface;
     
    +    //flag for case when appView is null during onStart
    +    private boolean shouldHandleStartOnAppViewInit = false;
    --- End diff --
    
    The webview (and thus plugins) are generally created from onCreate(), which means they will be initialized before the first call to onStart. If you're unit tests passes without this flag (and without the one in CordovaWebViewImpl), then I think you should remove them. It's not obvious (to me anyways) that this behaviour would even be the desired behaviour. If there's a reason it needs to be this way, then let me know! But if so, then we should upated onResume as well so that we're consistent.


---
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