I am getting this runtime exception about once every thousand+ sessions on the app, so it is rare and I have not been able to reproduce it.
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:381)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:226)
at android.view.Window$LocalWindowManager.removeView(Window.java:432)
at android.app.Dialog.dismissDialog(Dialog.java:278)
at android.app.Dialog.access$000(Dialog.java:71)
at android.app.Dialog$1.run(Dialog.java:111)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
at dalvik.system.NativeStart.main(Native Method)
Would anyone know how to reproduce it, or why it happens? Or better yet, how to fix it? :)
Thanks!
EDIT:
I added the suggestion made by Raghav to add this:
<activity android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name="ActivityName">
But this has not fixed the crashing and the crashing is still happening.
EDIT:
Here is some typical code I use:
public class ProblemActivity extends BaseListActivity
{
Dialog dialog;
....
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
...
// After some action
dialog.show();
}
public class GetSolutionTopicsTask extends AsyncTask<String, Void, String>
{
@Override
protected String doInBackground(String... theParams)
{
String myUrl = theParams[0];
String problem_id = theParams[1];
String charset = "UTF-8";
String response = null;
try
{
String query = String.format("problem_id=%s",
URLEncoder.encode(problem_id, charset));
final URL url = new URL( myUrl + "?" + query );
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.connect();
final InputStream is = conn.getInputStream();
final byte[] buffer = new byte[8196];
int readCount;
final StringBuilder builder = new StringBuilder();
while ((readCount = is.read(buffer)) > -1)
{
builder.append(new String(buffer, 0, readCount));
}
response = builder.toString();
}
catch (Exception e)
{
}
return response;
}
@Override
protected void onPostExecute(String result)
{
if ( result == null )
{
try
{
dialog.dismiss();
} catch (Exception e) {
// nothing
}
}
else
{
try
{
dialog.dismiss();
}
catch (Exception e)
{
// nothing
}
} // End of else
}
}
ConfigChanges are not causing this issue.
From the above logs it seems, that a dialog which was displayed in the activity was being dismissed after the activity is no longer visible.
If you shared the code or atleast give the steps you perform to get the crash, I can suggest a fix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With