带有 CopyBackForwardList 的 CustomWebViewRenderer DownloadManager 问题 [英] CustomWebViewRenderer DownloadManager issue with CopyBackForwardList

查看:22
本文介绍了带有 CopyBackForwardList 的 CustomWebViewRenderer DownloadManager 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍在学习 android,我正在使用这个 推荐.一切正常,但是当我完成下载文件时无法返回时,我正在尝试使用 copyBackForwardList 方法,但我不确定如何将 Xamarin.Forms.WebView 转换为 Android.Webkit.WebView 以使用 CopyBackForwardList 并使用其他 推荐

我正在尝试这样的事情

 protected override bool OnBackButtonPressed(){base.OnBackButtonPressed();String historyUrl = "";int i = 0;WebBackForwardList mWebBackForwardList = (Android.Webkit.WebView)browser;如果 (mWebBackForwardList.getCurrentIndex() > 0){while (i 

解决方案

您是否考虑过这可能是与 Android 的 Activity 生命周期相关的问题?一旦您在下载文件后提到了问题,并且根据您提供的参考资料 - 通过下载文件,包含 WebView 的活动不再是前台活动.所以,我想建议以下代码(抱歉在这里使用 Java):

//...私人 WebView 浏览器;私人捆绑包;@覆盖public void onCreate(final Bundle savedInstanceState){//...如果(捆绑!= null){browser.restoreState(bundle);}别的{browser.loadUrl("https://stackoverflow.com");//例如}//...}@覆盖公共无效 onPause(){super.onPause();捆绑=新捆绑();browser.saveState(bundle);}//...

这段代码的目的是在主 Activity 退出前台时保存 WebView 对象(浏览器)状态,将其状态保存在 Bundle(捆绑)对象中.

I´m still learning android, I'm creating a hybrid app using this recommendation. All works fine, but when i finish downloading a file i cant go back, I'm trying to use copyBackForwardList Method but im not sure how to convert Xamarin.Forms.WebView to Android.Webkit.WebView to use CopyBackForwardList and use this other recommendation

I'm trying something like this

    protected override bool OnBackButtonPressed()
    {
        base.OnBackButtonPressed();

        String historyUrl = "";
        int i = 0;
        WebBackForwardList mWebBackForwardList = (Android.Webkit.WebView)browser;
        if (mWebBackForwardList.getCurrentIndex() > 0)
        {
            while (i < mWebBackForwardList.getCurrentIndex())
            {
                historyUrl = mWebBackForwardList.getItemAtIndex(mWebBackForwardList.getCurrentIndex() - ++i).getUrl();
                if (historyUrl != null)
                {
                    browser.Source = historyUrl;
                    Content = browser;
                }
            }
        }


        return true;
    }

解决方案

Have You considered this can be an issue related to Android's Activity life cycle? Once You have referred to the problem after downloading a file, and from the reference You have provided - by downloading the file, the Activity containing the WebView is not the foreground one anymore. So, I would like to suggest the following code (sorry for using Java here):

// ... 

private WebView browser;
private Bundle bundle; 

@Override
public void onCreate(final Bundle savedInstanceState)
{
    // ...

    if (bundle != null)
    {
        browser.restoreState(bundle);
    }
    else
    {
        browser.loadUrl("https://stackoverflow.com"); // e.g.
    }

    // ...    

}

@Override
public void onPause()
{
    super.onPause();
    bundle = new Bundle();
    browser.saveState(bundle);

}

// ...

The purpose of this code stands for saving the WebView object (browser) state when the main Activity exits the foreground, by saving its state within the Bundle (bundle) object.

这篇关于带有 CopyBackForwardList 的 CustomWebViewRenderer DownloadManager 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆