激起我開始使用這種方式新的活動如下未捕獲的處理程序:螺紋主力退出,由於未捕獲的異常
Intent edit = new Intent(getParent(), WebViewLink.class);
TabGroupActivity parentActivity = (TabGroupActivity) getParent();
edit.putExtra(POSITION, FAQ);
parentActivity.startChildActivity("WebViewLink", edit);
我收到錯誤這樣
08-19 13:44:49.955: ERROR/AndroidRuntime(548): Uncaught handler: thread main exiting due to uncaught exception
08-19 13:44:49.974: ERROR/AndroidRuntime(548): android.view.WindowManager$BadTokenException: Unable to add window -- token [email protected] is not valid; is your activity running?
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.view.ViewRoot.setView(ViewRoot.java:468)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.app.Dialog.show(Dialog.java:239)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at com.stress.WebViewLink$2.onLoadResource(WebViewLink.java:73)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:355)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.os.Looper.loop(Looper.java:123)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.app.ActivityThread.main(ActivityThread.java:4363)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at java.lang.reflect.Method.invoke(Method.java:521)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at dalvik.system.NativeStart.main(Native Method)
,但是當我使用這種方式撥打新活動沒有問題
Intent edit = new Intent(getParent(), WebViewLink.class);
edit.putExtra(POSITION, FAQ);
More.this.startActivity(edit);
你可以在這裏看到我的WebViewLink.java類
public class WebViewLink extends Activity {
public static String POSITION = "position";
int position = 0;
private Button back;
private TextView ttl;
ProgressDialog myProgressDialog = null;
private WebView webView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webview);
back = (Button) findViewById(R.id.backtomore);
ttl = (TextView) findViewById(R.id.my_title);
webView.getSettings().setJavaScriptEnabled(true);
if (getIntent().getExtras() != null) {
if (getIntent().getExtras().containsKey(POSITION)) {
position = getIntent().getExtras().getInt(POSITION);
}
}
switch (position) {
case More.FAQ:
ttl.setText("FAQ");
setWebLink();
webView.loadUrl("file:///android_asset/faq4.htm");
break;
case More.ABOUT_US:
ttl.setText("About Us");
setWebLink();
webView.loadUrl("file:///android_asset/Advice/About Us.html");
break;
case More.DISCLAIMMER:
ttl.setText("Disclaimer");
setWebLink();
webView.loadUrl("file:///android_asset/Advice/Disclaimer.html");
break;
}
back.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
private void setWebLink() {
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onLoadResource(WebView view, String url) {
if (myProgressDialog == null) {
myProgressDialog = new ProgressDialog(WebViewLink.this);
myProgressDialog.setMessage("Loading.... Please Wait");
myProgressDialog.show();
}
}
public void onPageFinished(WebView view, String url) {
if (myProgressDialog.isShowing()) {
myProgressDialog.dismiss();
}
}
});
}
}
確定其工作很好謝謝很多 –