2013-10-28 64 views
1

我有一個web視圖,加載一個外部的JavaScript移動應用程序,這是不是我的應用程序,所以我不能操縱它。停止從定期請求webview

這個JavaScript應用程序的問題:它不斷地調用某個url。 在WebViewClient.shouldInterceptRequest方法中,我記錄了被調用的url。 這是輸出:

10-28 21:40:38.701: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996438694&_=1382996438703 
10-28 21:40:40.770: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996440763&_=1382996440775 
10-28 21:40:42.880: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996442873&_=1382996442880 
10-28 21:40:44.940: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996444934&_=1382996444942 
10-28 21:40:47.000: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996446993&_=1382996447001 
10-28 21:40:49.070: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996449044&_=1382996449053 
10-28 21:40:51.120: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996451114&_=1382996451125 
10-28 21:40:53.180: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996453166&_=1382996453180 
10-28 21:40:55.240: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996455237&_=1382996455244 
10-28 21:40:57.710: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996457295&_=1382996457714 
10-28 21:40:59.770: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996459766&_=1382996459773 
10-28 21:41:01.822: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996461813&_=1382996461820 
10-28 21:41:03.871: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996463864&_=1382996463871 
10-28 21:41:05.920: E/(1335): Loading https://m.tipico.com/ajax/login/register?cv=v4.23b440&c=1382996465914&_=1382996465921 

所以你可以看到。每50到60毫秒會自動發出一個請求。我想知道我怎麼能阻止這樣做?

任何建議?

回答

0

嘗試重寫shouldOverrideUrlLoading如下:

public class MyWebClient extends WebViewClient { 
    ... 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 

     if(url.startsWith("https://m.tipico.com/ajax/login/register")) { 
      return true; 
     } 

     return false; 
    } 

    ... 
}