ダイアログ ボックスが開き、ソーシャル ネットワーク アイコンのリストが表示されるアクティビティがあります。アイコンをクリックすると、ブラウザではなく同じアプリでサイトが開きますが、ユーザー名とパスワードを入力してログインすると問題が発生し、次のような例外が表示されます。
12-27 14:16:14.062: E/AndroidRuntime(4052): FATAL EXCEPTION: main
12-27 14:16:14.062: E/AndroidRuntime(4052): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@41c59680 is not valid; is your activity running?
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.view.ViewRootImpl.setView(ViewRootImpl.java:513)
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:301)
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.view.Window$LocalWindowManager.addView(Window.java:537)
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.app.Dialog.show(Dialog.java:278)
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.webkit.WebView.onSavePassword(WebView.java:1402)
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:442)
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.os.Looper.loop(Looper.java:137)
12-27 14:16:14.062: E/AndroidRuntime(4052): at android.app.ActivityThread.main(ActivityThread.java:4424)
12-27 14:16:14.062: E/AndroidRuntime(4052): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 14:16:14.062: E/AndroidRuntime(4052): at java.lang.reflect.Method.invoke(Method.java:511)
12-27 14:16:14.062: E/AndroidRuntime(4052): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-27 14:16:14.062: E/AndroidRuntime(4052): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-27 14:16:14.062: E/AndroidRuntime(4052): at dalvik.system.NativeStart.main(Native Method)
12-27 14:16:14.605: I/dalvikvm(4052): threadid=3: reacting to signal 3
12-27 14:16:14.613: I/dalvikvm(4052): Wrote stack traces to '/data/anr/traces.txt'
12-27 14:16:16.273: I/Process(4052): Sending signal. PID: 4052 SIG: 9
ここに私のコードがあります:
public class ShareActivity extends Activity implements OnItemClickListener {
//public static ShareActivity context;
WebView wv;
boolean land_scape=false;
ProgressDialog pdlg;
String links[]= new String[]{"Facebook","Twitter","Google Plus","Pintrest"};
ListView lv1;
Dialog dialog ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int currentOrientation = getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
land_scape=true;
}
else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
land_scape=false;
}
setContentView(R.layout.share_layout);
//context=this;
wv=(WebView)findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);
dialog = new Dialog(ShareActivity.this.getParent());
dialog.setTitle("Please select");
dialog.setCanceledOnTouchOutside(false);
dialog.setContentView(R.layout.share_list);
lv1=(ListView)dialog.findViewById(R.id.listShare);
lv1.setAdapter(new CustomShareAdapter(this,links));
lv1.setOnItemClickListener(this);
dialog.show();
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
switch(arg2)
{
case 0:
wv.loadUrl("http://www.facebook.com");
break;
case 1:
wv.loadUrl("https://mobile.twitter.com/login");
break;
case 2:
wv.loadUrl("http://www.plus.google.com");
break;
case 3:
wv.loadUrl("http://www.pinterest.com");
break;
}
wv.setWebViewClient(new WebViewClient());
dialog.dismiss();
}
@Override
public void onResume()
{
//Determine screen size
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
//Toast.makeText(this, "Large screen set to landscape",Toast.LENGTH_LONG).show();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
land_scape=true;
}
else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
//Toast.makeText(this, "Normal sized screen set to portrait" , Toast.LENGTH_LONG).show();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
land_scape=false;
}
else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
// Toast.makeText(this, "Small sized screen set to portrait " , Toast.LENGTH_LONG).show();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
land_scape=false;
}
else {
//Toast.makeText(this, "Screen size is neither large, normal or small" , Toast.LENGTH_LONG).show();
land_scape=false;
}
super.onResume();
}
@Override
public void onBackPressed() {
Intent backIntent = new Intent(this, MainActivity.class);
startActivity(backIntent);
super.onBackPressed();
}
}
2 番目の質問: 設定していない空の画面も表示されます。私はこの点について多くのことを検索しました。私を助けてください。