2013-06-25 33 views
0

我正在使用一個應用程序,所有webViews使用相同的活動,因爲唯一需要改變的是它加載的網址。我有一個加載對話框彈出,否則它只是白色的頁面。問題是,除了當我從主要活動啓動網頁活動時,加載對話框都適用於每個實例。這是主要活動的啓動代碼。不同的按鈕改變了意圖。Android - 加載對話框沒有出現,當一個活動啓動,但只有來自某些活動

編輯:通過不工作,我的意思是它加載網頁,但沒有對話框彈出,它只是在一個白色的屏幕坐作爲,如果我沒有shouldOverrideUrlLoading可言。它甚至不打印我放在那裏的調試信息。它確實使用我的新webClient,因爲它沒有任何默認功能。所以基本上,shouldOverrideUrlLoading不會被調用(但onPageFinished是)

編輯2:我忘了,logcat中也輸出nativeDestroy查看從標籤webViewGlue

Intent i = null; 
    // check which button was pressed, and then create the new intent 
    if (v == btnParticipants) { 
     i = new Intent(this, DetailedList.class); 
     i.putExtra("choice", Constants.SPONSOR_PAGE); 
    } else if (v == btnDirectionMap) { 
     i = new Intent(this, DirectionMapActivity.class); 
    } else if (v == btnEventMap) { 
     i = new Intent(this, EventMapActivity.class); 
    } else if (v == btnSchedule) { 
     i = new Intent(this, DetailedList.class); 
     i.putExtra("choice", Constants.ATTRACTION_PAGE); 
    } else if (v == btnSavedSchedule) { 
     i = new Intent(this, DetailedList.class); 
     i.putExtra("choice", Constants.MY_ATTRACTIONS); 
    } else if (v == btnRegistration) { 
     i = new Intent(this, Webpage.class); 
     i.putExtra("url", RetrievalEngine.getInstance().mainEvent.eventWebsite); 
    } else if (v == btnQR) { 

    } else if (v == btnFacebook) { 

    } else if (v == btnTwitter) { 
     i = new Intent(this, TwitterActivity.class); 
    } else if (v == btnWebsite) { 

    } else if (v == btnAbout) { 
     i = new Intent(this, AboutScreen.class); 
    } 

    // if a new intent was created, start it 
    if (i != null) { 
     startActivity(i); 
    } 

代碼不工作,但此人做它是從約頁面,v是一個視圖(按鈕,在這種情況下):

if (v == btnWebsite){ 
     Intent i = new Intent(this, Webpage.class); 
     i.putExtra("url", url); 
     startActivity(i); 
    } 

兩者都做同樣的事情,所以我想不通爲什麼它不工作。

而且,這裏是網頁活動:

WebView webView; 
static ProgressDialog mProgressDialog; 

@Override 
public boolean onKeyUp(int keyCode, KeyEvent event) { 
    this.finish(); 
    return super.onKeyUp(keyCode, event); 
} 

public void onFinish(){ 
    webView.destroy(); 
} 

@SuppressLint("SetJavaScriptEnabled") 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.web); 
    mProgressDialog = new ProgressDialog(this); 
    webView = (WebView) findViewById(R.id.webView); 
    Button backBtn = (Button) findViewById(R.id.backButton); 
    final TextView lbl = (TextView)findViewById(R.id.webPageDesc); 
    lbl.setText("Loading..."); 
    backBtn.setText("Back"); 
    backBtn.setOnClickListener(new OnClickListener(){ 

     public void onClick(View viewArg) { 
      WebView view = (WebView) findViewById(R.id.webView); 
      if (view.canGoBack()) { 
       view.goBack(); 
      } 
     } 
    }); 

    webView.getSettings().setBuiltInZoomControls(true); 
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.setWebViewClient(new WebViewClient() { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      lbl.setText("Loading..."); 

      mProgressDialog.setTitle("Loading"); 
      try{ 
       mProgressDialog.show(); 
      }catch(Exception e){} 
      mProgressDialog.setMessage("Loading " + url); 
      return false; 
     } 

     @Override 
     public void onPageFinished(WebView view, String url) { 
      mProgressDialog.dismiss(); 
      if(view.getTitle().length() > 33){ 
       lbl.setText(view.getTitle().substring(0, 30) + "..."); 
      }else{ 
       lbl.setText(view.getTitle()); 
      } 
      view.setVisibility(View.VISIBLE); 
      super.onPageFinished(view, url); 
     } 
    }); 

    Bundle extras = getIntent().getExtras(); 
    if (extras != null) { 
     String url = extras.getString("url"); 
     webView.loadUrl(url); 
    } 
} 
+1

定義「不起作用」。它會崩潰嗎?如果是這樣,請發佈logcat – codeMagic

+0

更新的問題。 – TheBat

+0

'if/else'mess - 你沒有聽說過'switch/case'嗎? –

回答

0

我從shouldOverrideUrlLoading到onPageStarted移動的代碼,它的工作。

相關問題