你好在我的应用程序中我正在使用 TabHost
http://ericharlow.blogspot.in/2010/09/experience-multiple-android-activities.html
现在,我在 webview 中打开 twitter 选项卡、facebook 选项卡页,它已成功加载,但在登录时,如果我在传递用户名和密码后按下登录按钮,应用程序崩溃并会发生以下错误。
02-28 18:58:17.519: E/AndroidRuntime(10604): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@4051ec60 is not valid; is your activity running?
02-28 18:58:17.519: E/AndroidRuntime(10604): at android.view.ViewRoot.setView(ViewRoot.java:528)
02-28 18:58:17.519: E/AndroidRuntime(10604): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
02-28 18:58:17.519: E/AndroidRuntime(10604): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
02-28 18:58:17.519: E/AndroidRuntime(10604): at android.view.Window$LocalWindowManager.addView(Window.java:465)
02-28 18:58:17.519: E/AndroidRuntime(10604): at android.app.Dialog.show(Dialog.java:241)
02-28 18:58:17.519: E/AndroidRuntime(10604): at android.app.AlertDialog$Builder.show(AlertDialog.java:813)
02-28 18:58:17.519: E/AndroidRuntime(10604): at android.webkit.WebView.onSavePassword(WebView.java:1123)
02-28 18:58:17.519: E/AndroidRuntime(10604): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:424)
02-28 18:58:17.519: E/AndroidRuntime(10604): at android.os.Handler.dispatchMessage(Handler.java:99)
02-28 18:58:17.519: E/AndroidRuntime(10604): at android.os.Looper.loop(Looper.java:130)
02-28 18:58:17.519: E/AndroidRuntime(10604): at android.app.ActivityThread.main(ActivityThread.java:3835)
02-28 18:58:17.519: E/AndroidRuntime(10604): at java.lang.reflect.Method.invokeNative(Native Method)
我加载 facebook 页面或 twitter 页面的类是
public class FacebookActivity extends Activity implements OnClickListener {
private WebView mWebView;
ProgressDialog PD;
String sabNZBurl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.facebook);
sabNZBurl = getResources().getString(R.string.fburl);
mWebView = (WebView) findViewById(R.id.webView1);
// Added by Pankit -------- start
if (!TabSample.checkForInternet.isNetworkAvailable(this, this)) {
Toast.makeText(TabSample.tabContext,
"No Net Connection... Exiting...", 2000).show();
exitOnNoNetConnection();
} else {
// Added by Pankit -------- End
PD = new ProgressDialog(TabSample.tabContext);
PD.setMessage("Please Wait......");
PD.show();
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.loadUrl(sabNZBurl);
}
}
final class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
PD.dismiss();
}
}