So basically I’m using a TabGroupActivity inside my TabHost,so I can switch different activities inside of one tab.Two days before the code that I’m running right now was ok,without any exceptions.But in that time I was flipping views inside the tab.Now I change all views with different activities.So my situation is something like that:
Main tab Activity -> opens Second activity -> which opens the third activity ,where the AlertDialog is.
The code I’m using is that :
Button deactivate = (Button) findViewById(R.id.deactivate);
deactivate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new AlertDialog.Builder( getParent() )
.setTitle( "Warning" )
.setMessage( "The collection will be removed completely from the device.You can reactivate it later again.This operation requires internet connection." )
.setPositiveButton( "Go ahead", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.d("AlertDialog", "Positive");
}
})
.setNegativeButton( "Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.d("AlertDialog","Negative");
}
})
.show();
}
});
and the Exception is :
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): FATAL EXCEPTION: main
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@463430d0 is not valid; is your activity running?
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.view.ViewRoot.setView(ViewRoot.java:509)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.app.Dialog.show(Dialog.java:241)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at com.stampii.stampii.mystampii.MyCollectionId$4.onClick(MyCollectionId.java:74)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.view.View.performClick(View.java:2408)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.view.View$PerformClick.run(View.java:8817)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.os.Handler.handleCallback(Handler.java:587)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.os.Handler.dispatchMessage(Handler.java:92)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.os.Looper.loop(Looper.java:144)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at android.app.ActivityThread.main(ActivityThread.java:4937)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at java.lang.reflect.Method.invoke(Method.java:521)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-14 11:08:33.254: ERROR/AndroidRuntime(4726): at dalvik.system.NativeStart.main(Native Method)
I tried with this, MyCollecionId.this, with adding Context ad etc.but I can’t get the things to work.Any ideas how to solve that problem?
try it out, pass your running activity’s context