Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
997 views
in Technique[技术] by (71.8m points)

cordova - Android WebView prevent page reload

I have a Phonegap packaged application that opens a PDF Viewer when a button is pressed. I did it with the FileOpener2 plugin.

When I go back to the application from the PDF Viewer, the result differs depending on Android versions.

In Android 4.* the application stays where it should be before leaving the application. However, in Android 2.3.7 the WebView reloads the application, which is the behaviour I don′t expect.

I already tried changing android:launchmode to singleTask or singleInstance with no success.

How can I avoid page reload when I came back to the Phonegap application?

Thanks in advance!

Update 1

I have modified the Cordova or Phonegap class CordovaWebViewClient which extends WebViewClient with:

@Override
public void onLoadResource(WebView view, String url) {
    if (url.equals("file:///android_asset/www/index.html")) {
        if (this.firstLoad) {
            this.firstLoad = false;
        } else {
            view.stopLoading();
        }
    }

However the onLoadResource only gets fired when the application started and not when it resumes from another application.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Answering my own question, setting the following properties to the only Acivity in AndroidManifest solves the problem. However I have to test it because it could have problems that I don't know:

android:launchMode="singleInstance"
android:alwaysRetainTaskState="true"

Cheers!

Update

After testing a bug appeared selection a photo in the Gallery with Phonegap Camera plugin that shows "Selection cancelled".

So after reading https://groups.google.com/forum/#!topic/phonegap/R08vOZNm580 I set:

 android:launchMode="singleTask"
 android:taskAffinity=""
 android:excludeFromRecents="true"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...