Giter Site home page Giter Site logo

Comments (10)

snailycy avatar snailycy commented on May 2, 2024 3

受腾讯的文档启发,试着实现了WebView池:
https://github.com/snailycy/AndroidHybridLib/blob/master/hybridlib/src/main/java/com/github/snailycy/hybridlib/webview/WebViewPool.java

from vassonic.

vasdeveloper avatar vasdeveloper commented on May 2, 2024

webview复用池不在sonic项目中,webview复用的难点在于context的设置,其他的没有太特殊的逻辑。

from vassonic.

zhangyunhua avatar zhangyunhua commented on May 2, 2024

我使用webview复用池,初次用没问题。 但是当复用时,点击back键,webview.canGoBack() 居然为true,当执行webview.goback()时会返回到我第一使用时的webview页面。

但是在回收时已经执行了 stopLoading(); clearCache(true); clearHistory(); 这些清空操作。

现在卡在这里了,不知道该如何解决了

from vassonic.

free46000 avatar free46000 commented on May 2, 2024

webview.clearHistory() 会保留当前页的,所以这块需要自己处理一下,判断如果是最后的页面让canGoBack返回false

from vassonic.

vasdeveloper avatar vasdeveloper commented on May 2, 2024

@free46000 @zhangyunhua
由于WebView中loadUrl、stopLoading等接口调用在内核基本都是异步执行,可能存在任务在消息池子里面还没有执行到,建议的方式是:
1.销毁前先调用loadUrl("about:blank"),然后延迟1s后调用clearHistory,使用前再调用一次clearHistory;
2.如果还担心存在风险,参照free的方式进行canGoBack判断。

from vassonic.

free46000 avatar free46000 commented on May 2, 2024

@vasdeveloper @zhangyunhua
补充下,调用完loadUrl("about:blank"),可以在WebViewClient#doUpdateVisitedHistory中执行clearHistory操作,这样能保证当前WebView历史中只有about:blank

from vassonic.

ian-cuc avatar ian-cuc commented on May 2, 2024

现在的有一个问题,就是我就算执行了 loadUrl("about:blank") ,有时候打开新的页面复用的时候,会短暂的显示上一个页面的内容,这个有什么好的方法吗

from vassonic.

free46000 avatar free46000 commented on May 2, 2024

@ian-cuc 你说的上一个页面指的是 about:blank 页,还是about:blank页之前的页面

  • about:blank页是一个空白页,可以忽略此问题吧,(也可以加载一个透明的html页)
  • 如果是about:blank页之前的页面,那肯定是没有 load 成功,可以看看代码逻辑

from vassonic.

yunnywu avatar yunnywu commented on May 2, 2024

我最后的做法 判断goback 加个判断,防止后退到之前的页面
if(!mWebView.getUrl().equals(url)) {
mWebView.goBack();
return true;
}

同时在reset 的时候执行
webView.loadUrl("about:blank");
Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@OverRide
public void run() {
webView.clearHistory();
}
}, 500);

试了很多次 没出现问题了

from vassonic.

zengcanxiang avatar zengcanxiang commented on May 2, 2024

@snailycy @zhangyunhua 在webview的复用池使用context更换的方案,你们有兼容zoom放大缩小崩溃的问题么? 当没有使用复用的时候,直接使用Activity初始化对象就不崩溃. 否则就会崩溃

from vassonic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.