jquery freeze on supspend/resume in webview

since two years i am searching for the mistake

When the app is started there is no problem of opening different views and do some stuff. But when the application goes in background for some period of time (as far as it happens between 10minutes and 2-3 hours) and after resuming the application the user interface is frozen and nothing is responding also no error is printed in logcat. We have to kill the application and restart it to make it work.

i minimalized the code to give a minimal code example of my problem

main activity:

package com.example.test;
import com.example.test.HTML5WebView;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity 
{
HTML5WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    this.getActionBar().hide();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    myWebView = new HTML5WebView(this);
    setContentView(myWebView.getLayout());
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.loadUrl("https://www.gamesonly.at/mobile/index.asp?apid=AV2:");
}
}

HTML5WebView:

        package com.example.test;

    import com.example.test.R;
    import com.example.test.R.id;
    import com.example.test.R.layout;


    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.util.AttributeSet;
    import android.view.KeyEvent;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.Window;
    import android.webkit.CookieSyncManager;
    import android.webkit.GeolocationPermissions;
    import android.webkit.WebChromeClient;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.FrameLayout;

public class HTML5WebView extends WebView {

private Context                             mContext;
private MyWebChromeClient                   mWebChromeClient;
private View                                mCustomView;
private FrameLayout                         mCustomViewContainer;
private WebChromeClient.CustomViewCallback  mCustomViewCallback;

private FrameLayout                         mContentView;
private FrameLayout                         mBrowserFrameLayout;
private FrameLayout                         mLayout;
public ProgressDialog progress;
public String last_known_url = null;

static final String LOGTAG = "HTML5WebView";

private void init(Context context) {
    mContext = context;     
    Activity a = (Activity) mContext;

    mLayout = new FrameLayout(context);

    mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(a).inflate(R.layout.custom_screen, null);
    mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.main_content);
    mCustomViewContainer = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.fullscreen_custom_content);

    mLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);

    // Configure the webview
    WebSettings s = getSettings();
    s.setBuiltInZoomControls(true);
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    s.setUseWideViewPort(true);
    s.setLoadWithOverviewMode(true);
  //  s.setSavePassword(true);
    s.setSaveFormData(true);
    s.setJavaScriptEnabled(true);
    s.setDomStorageEnabled(true);
    s.setCacheMode(WebSettings.LOAD_NO_CACHE); 
    s.setDatabaseEnabled(true);

    mWebChromeClient = new MyWebChromeClient();
    setWebChromeClient(mWebChromeClient);


    setWebViewClient(new WebViewClient(){

         public void onPageFinished(WebView view, String url) {

             progressloading_hide();

             System.out.println("onPageFinished url: " +url);
                // Facebook redirects to this url once a user has logged in, this is a blank page so we override this
                // http://www.facebook.com/connect/connect_to_external_page_widget_loggedin.php?............
                if(url.startsWith("https://www.facebook.com/plugins/close_popup.php")){
                    String redirectUrl = "https://www.gamesonly.at/android_v6/index.asp";
                    view.loadUrl(redirectUrl);
                    return;
                }


                super.onPageFinished(view, url);



    };



        public boolean shouldOverrideUrlLoading(WebView view, String url) {

        {
            //System.out.println("ERKANNT: shouldOverrideUrlLoading"+url.toLowerCase());
              if(url.toLowerCase().startsWith("http") || url.toLowerCase().startsWith("https") || url.toLowerCase().startsWith("file"))
                {

                   //            System.out.println("shouldOverrideUrlLoading=FALSE STANDARD HANDLING");
                               return(false);
                }
                else
                {
                //  System.out.println("shouldOverrideUrlLoading=URL SCHEMA CALL?");
                                try
                                {
                                                Uri uri = Uri.parse(url);
                                                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                                                view.getContext().startActivity(intent);
                                                return (true);
                                }
                                catch (Exception e)
                                {
                     //             System.out.println("shouldOverrideUrlLoading ERROR "+e.getMessage());
                                    return (true);
                                }
                }

        } 
        }

    });


    // enable navigator.geolocation 
   // s.setGeolocationEnabled(true);
   // s.setGeolocationDatabasePath("/data/data/org.itri.html5webview/databases/");

    // enable Web Storage: localStorage, sessionStorage
    s.setDomStorageEnabled(true);

    mContentView.addView(this);
}

public void progressloading_show(Context context) {
    if (progress==null)
            progress = new ProgressDialog(context);

    progress.setTitle("Bitte warten");
    progress.setMessage("Lade Daten...");
    progress.show();
    // To dismiss the dialog
    //progress.dismiss();
}

public void progressloading_hide() {
    if (progress!=null){
        if (progress.isShowing())
            progress.dismiss();
    }
}


public HTML5WebView(Context context) {
    super(context);
    init(context);
}

public HTML5WebView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context);
}

public HTML5WebView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(context);
}

public FrameLayout getLayout() {
    return mLayout;
}

public boolean inCustomView() {
    return (mCustomView != null);
}

public void hideCustomView() {
    mWebChromeClient.onHideCustomView();
    System.out.println("System.out.onHideCustomView");
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if ((mCustomView == null) && canGoBack()){
            goBack();
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}



private class MyWebChromeClient extends WebChromeClient {
    private View        mVideoProgressView;


    @Override
    public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)
    {
        //System.out.println("customview show");
        HTML5WebView.this.setVisibility(View.GONE);
        System.out.println("System.out.HTML5WebView GONE");
        // if a view already exists then immediately terminate the new one
        if (mCustomView != null) {
            callback.onCustomViewHidden();
            return;
        }

        mCustomViewContainer.addView(view);
        mCustomView = view;
        mCustomViewCallback = callback;
        mCustomViewContainer.setVisibility(View.VISIBLE);
        System.out.println("System.out.mCustomViewContainer VISIBLE");
    }

    @Override
    public void onHideCustomView() {
        //System.out.println("customview hideeeeeeeeeeeeeeeeeeeeeeeeeee");
        if (mCustomView == null)
            return;        

        // Hide the custom view.
        mCustomView.setVisibility(View.GONE);
        System.out.println("System.out.mCustomView GONE");
        // Remove the custom view from its container.
        mCustomViewContainer.removeView(mCustomView);
        mCustomView = null;
        mCustomViewContainer.setVisibility(View.GONE);
        mCustomViewCallback.onCustomViewHidden();
       // if (canGoForward())
       //   HTML5WebView.this.goForward();
        HTML5WebView.this.setVisibility(View.VISIBLE);
        System.out.println("System.out.HTML5WebView VISIBLE");
    //    HTML5WebView.this.goBack();
        //Log.i(LOGTAG, "set it to webVew");
    }


    @Override
    public View getVideoLoadingProgressView() {
        //Log.i(LOGTAG, "here in on getVideoLoadingPregressView");

        if (mVideoProgressView == null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null);
        }
        return mVideoProgressView; 
    }

     @Override
     public void onReceivedTitle(WebView view, String title) {
        ((Activity) mContext).setTitle(title);
     }

     @Override
     public void onProgressChanged(WebView view, int newProgress) {
         ((Activity) mContext).getWindow().setFeatureInt(Window.FEATURE_PROGRESS, newProgress*100);
     }

     @Override
     public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
         callback.invoke(origin, true, false);
     }
}


static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
    new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}


Source: android

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.