亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 5525 | 回復(fù): 1
打印 上一主題 下一主題

[HBase] loadData與loadDataWithBaseURL的區(qū)別 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2011-11-10 20:25 |只看該作者 |倒序?yàn)g覽
loadData與loadDataWithBaseURL的區(qū)別





在寫WebView時(shí),感覺LoadUrl太浪費(fèi)流量,而且加載起來有點(diǎn)慢,就考慮用其它的方法來實(shí)現(xiàn)。在加載頁面時(shí),如果只加載數(shù)據(jù),頁面模板提前寫好放到項(xiàng)目中,這樣就可以來更快的加載頁面,用戶體驗(yàn)會(huì)好些。

      如果不用loadUrl,省下的就只有LoadData和loadDataWithBaseURL了,下面來說下LoadData和loadDataWithBaseURL 的用法;

  1.       loadData:

  2. public void loadData (String data, String mimeType, String encoding)
  3. Load the given data into the WebView. This will load the data into WebView using the data: scheme. Content loaded through this mechanism does not have the ability to load content from the network.

  4. Parameters
  5. data A String of data in the given encoding. The date must be URI-escaped -- '#', '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.
  6. mimeType The MIMEType of the data. i.e. text/html, image/jpeg
  7. encoding The encoding of the data. i.e. utf-8, base64
復(fù)制代碼
下如API中所說的,

      data:是要加載的數(shù)據(jù)類型,但在數(shù)據(jù)里面不能出現(xiàn)英文字符:'#', '%', '\' , '?' 這四個(gè)字符,如果有的話可以用 %23, %25, %27, %3f,這些字符來替換,在平時(shí)測試時(shí),你的數(shù)據(jù)時(shí),你的數(shù)據(jù)里含有這些字符,但不會(huì)出問題,當(dāng)出問題時(shí),你可以替換下。

       %,會(huì)報(bào)找不到頁面錯(cuò)誤,頁面全是亂碼。亂碼樣式見符件。

       #,會(huì)讓你的goBack失效,但canGoBAck是可以使用的。于是就會(huì)產(chǎn)生返回按鈕生效,但不能返回的情況。

       \ 和? 我在轉(zhuǎn)換時(shí),會(huì)報(bào)錯(cuò),因?yàn)樗鼤?huì)把\當(dāng)作轉(zhuǎn)義符來使用,如果用兩級(jí)轉(zhuǎn)義,也不生效,我是對(duì)它無語了。

我們?cè)谑褂胠oadData時(shí),就意味著需要把所有的非法字符全部轉(zhuǎn)換掉,這樣就會(huì)給運(yùn)行速度帶來很大的影響,因?yàn)樵谑褂脮r(shí),在頁面stytle中會(huì)使用很多%號(hào)。頁面的數(shù)據(jù)越多,運(yùn)行的速度就會(huì)越慢。

      data中,有人會(huì)遇到中文亂碼問題,解決辦法:參數(shù)傳"utf-8",頁面的編碼格式也必須是utf-8,這樣編碼統(tǒng)一就不會(huì)亂了。別的編碼我也沒有試過。
  1. public

  2. void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl)
  3. Load the given data into the WebView, use the provided URL as the base URL for the content. The base URL is the URL that represents the page that is loaded through this interface. As such, it is used to resolve any relative URLs. The historyUrl is used for the history entry.

  4. Note for post 1.0. Due to the change in the WebKit, the access to asset files through "file:///android_asset/" for the sub resources is more restricted. If you provide null or empty string as baseUrl, you won't be able to access asset files. If the baseUrl is anything other than http(s)/ftp(s)/about/javascript as scheme, you can access asset files for sub resources.

  5. Parameters
  6. baseUrl Url to resolve relative paths with, if null defaults to "about:blank"
  7. data A String of data in the given encoding.
  8. mimeType The MIMEType of the data. i.e. text/html. If null, defaults to "text/html"
  9. encoding The encoding of the data. i.e. utf-8, us-ascii
  10. historyUrl URL to use as the history entry. Can be null.
復(fù)制代碼
在使用loadDataWithBaseURL時(shí),需要注意的就是 baseUr:雖然API上寫的是要傳一個(gè)Url,但我在用時(shí),發(fā)現(xiàn)傳一個(gè)Url并不可以,我發(fā)現(xiàn)這個(gè)就是一個(gè)標(biāo)志位,用來標(biāo)志當(dāng)前頁面的Key值的,而historyUrl就是一個(gè)value值,在加載時(shí),它會(huì)把baseUrl和historyUrl傳到List列表中,當(dāng)作歷史記錄來使用,當(dāng)前進(jìn)和后退時(shí),它會(huì)通過baseUrl來尋找historyUrl的路徑來加載historyUrl路徑來加載歷史界面,需要注意的就是history所指向的必須是一個(gè)頁面,并且頁面存在于SD卡中或程序中(assets),loadDataWithBaseURL,它本身并不會(huì)向歷史記錄中存儲(chǔ)數(shù)據(jù),要想實(shí)現(xiàn)歷史記錄,需要我們自己來實(shí)現(xiàn),也許是我的技術(shù)有限,我有了比較笨的訪求來實(shí)現(xiàn):就是在加載頁面時(shí),我把數(shù)據(jù)另外的寫到一個(gè)html頁面中,并把它保存到SD中,當(dāng)點(diǎn)擊返回時(shí),它會(huì)通過historyUrl指向的路徑來加載頁面,這樣就解決了歷史記錄問題。



上面這兩種方法,我建議使用后者,雖然loadData的歷史記錄不需要我們自己來實(shí)現(xiàn),但在使用時(shí),我們必須把所有的%,#,\,?轉(zhuǎn)換掉,在轉(zhuǎn)換時(shí),也許會(huì)遇到別的困難,我也沒有測完。這就兩個(gè)加載上后者比前者快一到兩倍。

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2011-11-11 16:54 |只看該作者
樓主東西很好,以后常來往
小弟的帖子也來看看吧!
http://72891.cn/viewthr ... &extra=page%3D1
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP