Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

CHCP reload index.html page on screen wake #93

Closed
sckoh opened this issue Jan 18, 2016 · 23 comments
Closed

CHCP reload index.html page on screen wake #93

sckoh opened this issue Jan 18, 2016 · 23 comments

Comments

@sckoh
Copy link

sckoh commented Jan 18, 2016

CHCP reload the index.html page everytime i turn off screen and turn it back.

the log show:

D/CHCP﹕ Loading external page: /data/user/0/com.example.package/files/cordova-hot-code-push-plugin/2016-01-18T09:33:25.621Z/www/index.html

@nikDemyankov
Copy link
Member

My guess that this is on Android?

@sckoh
Copy link
Author

sckoh commented Jan 18, 2016

yes, is this a known issue?

@nikDemyankov nikDemyankov added this to the v1.2.5 milestone Jan 18, 2016
@nikDemyankov
Copy link
Member

Thanks for noticing, will fix that.

@sckoh
Copy link
Author

sckoh commented Jan 18, 2016

The reason it reload everytime on wake is on

https://github.com/nordnet/cordova-hot-code-push/blob/master/src/android/src/com/nordnetab/chcp/main/HotCodePushPlugin.java

line 115

it redirect to index.html in the onStart function which will be called everytime on screen wake

@nikDemyankov
Copy link
Member

Yes, that is correct. Found it when posted the first answer. But thanks for the help :)

Will add check, that if we already loaded correct index page - don't do it again.

@johnmiroki
Copy link

@nikDemyankov I noticed that the app is reloaded on every resume (on Android, haven't tested on iOS), even if I set {"update": "start"} in chcp.json. I'm wondering if this is affected by the same code you've mentioned.

@nikDemyankov
Copy link
Member

@johnmiroki yes, it doesn't depend on the chcp.json configuration. Page just get's reloaded, when application is awaken. Should be fine on iOS.

@johnmiroki
Copy link

@nikDemyankov I see. Thanks! Good to know it's gonna be fixed on next version bump. chcp.json.update only controls when the downloaded update actually replaces the old file. When the plugin checks for an update or reload the page is another story. right?

@nikDemyankov
Copy link
Member

@johnmiroki yes, chcp.json.update controls, when plugin installs the update. The reload problem, described in this issue, is just a bug, which is not related to that preference.

@sckoh
Copy link
Author

sckoh commented Jan 20, 2016

@johnmiroki I added a check in my fork to only reload page during app start or app update
https://github.com/sckoh/cordova-hot-code-push

@johnmiroki
Copy link

@sckoh Thanks a lot. Just tried on one android device quickly, the plugin doesn't reload the app on every resume any more at the very least. consider a pull-request?

@nikDemyankov
Copy link
Member

@sckoh good one :) Thanks for sharing.

But I should say, that it will not work properly for the update, that happens on the very first start. When application launched for the first time (or after being updated from the store) - it will exit on line 112. So the reload flag is false. Then update is installed - page gets reloaded from the external page. When user goes to home screen and resume the app - this time it will hit line 119 , but the page will be reloaded, although it was already loaded from external storage. But on every next start it should be fine.

nikDemyankov added a commit that referenced this issue Jan 20, 2016
@alexbuijs
Copy link
Contributor

There is a bug with your fix (taken from app with the recent master branch of your plugin):

E/AndroidRuntime(  815): FATAL EXCEPTION: main
E/AndroidRuntime(  815): Process: nl.staging.testapp, PID: 815
E/AndroidRuntime(  815): java.lang.RuntimeException: Unable to start activity ComponentInfo{nl.staging.testapp/nl.staging.testapp.MainActivity}: java.lang.NullPointerException
E/AndroidRuntime(  815):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
E/AndroidRuntime(  815):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
E/AndroidRuntime(  815):    at android.app.ActivityThread.access$800(ActivityThread.java:139)
E/AndroidRuntime(  815):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
E/AndroidRuntime(  815):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(  815):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(  815):    at android.app.ActivityThread.main(ActivityThread.java:5086)
E/AndroidRuntime(  815):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  815):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(  815):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/AndroidRuntime(  815):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/AndroidRuntime(  815):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  815): Caused by: java.lang.NullPointerException
E/AndroidRuntime(  815):    at com.nordnetab.chcp.main.HotCodePushPlugin.onStart(HotCodePushPlugin.java:122)
E/AndroidRuntime(  815):    at org.apache.cordova.PluginManager.onStart(PluginManager.java:276)
E/AndroidRuntime(  815):    at org.apache.cordova.CordovaWebViewImpl.handleStart(CordovaWebViewImpl.java:462)
E/AndroidRuntime(  815):    at org.apache.cordova.CordovaActivity.onStart(CordovaActivity.java:293)
E/AndroidRuntime(  815):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1194)
E/AndroidRuntime(  815):    at android.app.Activity.performStart(Activity.java:5258)
E/AndroidRuntime(  815):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)
E/AndroidRuntime(  815):    ... 11 more
W/ActivityManager( 1022):   Force finishing activity nl.staging.testapp/.MainActivity

It seems webView.getUrl() is null...

alexbuijs added a commit to alexbuijs/cordova-hot-code-push that referenced this issue Jan 26, 2016
@nikDemyankov
Copy link
Member

@alexbuijs Thanks for noticing. Strange that I didn't hit that.

Are you using crosswalk or something like that?

@alexbuijs
Copy link
Contributor

Yes, I am using crosswalk. Does that impact this plugin?

@nikDemyankov
Copy link
Member

Not so long ago I had a similar problem with crosswalk: in onStart() it didn't have any URL in the webView, although the default webView did. That's why I missed that in this fix: haven't checked it with crosswalk. But when you showed the crash log - it hit me. Will test it more with the crosswalk.

@alexbuijs
Copy link
Contributor

Awesome! Thanks for all your work on this great plugin! :-)

@nikDemyankov
Copy link
Member

Thanks :)

nikDemyankov added a commit that referenced this issue Feb 1, 2016
@guv3n
Copy link

guv3n commented Feb 4, 2016

Just encountered this bug when playing with the camera on an Android device. After the photo is taken or picked in the library, the app is resumed and index.html reloaded, which makes processing the pic impossible.
When do you plan to release 1.2.5 ?
Btw, iOS version of my app is currently being reviewed by Apple, and being able to update the app through the plugin will be a huge advantage. Thanks for it.

@nikDemyankov
Copy link
Member

Wanted to cleanup the fix a bit before the actual release. Probably will do this during the weekends, or on Monday.

@guv3n
Copy link

guv3n commented Feb 4, 2016

I don't know if it's related but :

  • I removed the hcp plugin
  • Added the current version using the git URL
    Then I could not run or build for android, got this error :
CHCP plugin after prepare hook:
ERROR running one or more of the platforms: TypeError: Cannot read property 'length' of undefined
You may not have the required environment or OS to run this project

After I removed the plugin and reinstalled 1.2.4, it worked again. I hope it helps.

@nikDemyankov
Copy link
Member

Yes, thanks. Didn't test it properly, so this is possible. That's why it is still not released.

@nikDemyankov
Copy link
Member

v1.2.5 is released. Should work now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants