Comments (10)
受腾讯的文档启发,试着实现了WebView池:
https://github.com/snailycy/AndroidHybridLib/blob/master/hybridlib/src/main/java/com/github/snailycy/hybridlib/webview/WebViewPool.java
from vassonic.
webview复用池不在sonic项目中,webview复用的难点在于context的设置,其他的没有太特殊的逻辑。
from vassonic.
我使用webview复用池,初次用没问题。 但是当复用时,点击back键,webview.canGoBack() 居然为true,当执行webview.goback()时会返回到我第一使用时的webview页面。
但是在回收时已经执行了 stopLoading(); clearCache(true); clearHistory(); 这些清空操作。
现在卡在这里了,不知道该如何解决了
from vassonic.
webview.clearHistory()
会保留当前页的,所以这块需要自己处理一下,判断如果是最后的页面让canGoBack
返回false
from vassonic.
@free46000 @zhangyunhua
由于WebView中loadUrl、stopLoading等接口调用在内核基本都是异步执行,可能存在任务在消息池子里面还没有执行到,建议的方式是:
1.销毁前先调用loadUrl("about:blank"),然后延迟1s后调用clearHistory,使用前再调用一次clearHistory;
2.如果还担心存在风险,参照free的方式进行canGoBack判断。
from vassonic.
@vasdeveloper @zhangyunhua
补充下,调用完loadUrl("about:blank")
,可以在WebViewClient#doUpdateVisitedHistory
中执行clearHistory
操作,这样能保证当前WebView
历史中只有about:blank
页
from vassonic.
现在的有一个问题,就是我就算执行了 loadUrl("about:blank") ,有时候打开新的页面复用的时候,会短暂的显示上一个页面的内容,这个有什么好的方法吗
from vassonic.
@ian-cuc 你说的上一个页面指的是 about:blank
页,还是about:blank
页之前的页面
about:blank
页是一个空白页,可以忽略此问题吧,(也可以加载一个透明的html页)- 如果是
about:blank
页之前的页面,那肯定是没有load
成功,可以看看代码逻辑
from vassonic.
我最后的做法 判断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.
@snailycy @zhangyunhua 在webview的复用池使用context更换的方案,你们有兼容zoom放大缩小崩溃的问题么? 当没有使用复用的时候,直接使用Activity初始化对象就不崩溃. 否则就会崩溃
from vassonic.
Related Issues (20)
- 360手机出现setResult: notify fail as webCallback is not set, please wait!
- iOS 使用cocoapod 添加不上库 现在框架还继续更新吗?
- Android Demo的请求responsecode是301 HOT 1
- 打开页面时,需要 back 多次,才能退出 WebView,中间会展示之前访问过的当前链接的页面内容
- WKWebView
- Weak Cryptographic Hash
- Cross-Site Scripting: Inter-Component Communication
- 有关UserAgent后面的Sonic/2.0.0的问题
- WKWebView HOT 3
- 页面乱码
- SDK能否添加oom捕获?
- 每次都加载 about:blank HOT 1
- 支持Google play应用市场吗? HOT 2
- 代码不维护更新了吗 HOT 1
- create sonic session fail! HOT 1
- KPI项目?不维护?
- Android 放一会再进去或者退出应用重进,又需要重新加载js等资源
- 该项目不维护了吗?是否还可以用 HOT 2
- JCenter service is shutting down
- VA
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vassonic.