title: Android : Strange error when returning a simple string from doInBackground
body: <p>This is the doInBackground code in question :-</p>
  
  <pre><code>@Override
      protected String doInBackground(Void... params) {
  
  
          try {
              jsonArray = LoadCacheAction();
  
              for (int i = 0; i &lt; jsonArray.length(); i++) {
                  JSONObject obj = jsonArray.getJSONObject(i);
                  HttpResponse httpResponse = httpResponse = ((Globals) getApplication()).SendDataApache("employeeactions", obj);;
  
                  if (httpResponse != null) {
                      int code = httpResponse.getStatusLine().getStatusCode();
                      if ((code == 200) || (code == 201)){
                          return "ok";
                      }
                      else if ((code == 400)){
                          ((Globals) getApplication()).WriteEventLogCache(((Globals) getApplication()).TodaysDate(), "3", "1", ((Globals) getApplication()).getIdUser(), "400 - Bad request error - Clocking Action");
                          return code + "";
                      }
                      else
                          return code + "";
                  }
              }
  
              ((Globals) getApplication()).WriteEventLogCache(((Globals) getApplication()).TodaysDate(), "3", "1", ((Globals) getApplication()).getIdUser(), "Just Testing");
  
              return "error";
  
          } catch (Exception e) {
              ((Globals) getApplication()).WriteEventLogCache(((Globals) getApplication()).TodaysDate(), "3", "1", ((Globals) getApplication()).getIdUser(), e.getMessage());
              return "conIssue";
          }
      }
  </code></pre>
  
  <p>The whole software package works perfectly right up until it hits any one of the returns.  When it does this the software crashes out completely.  I have tried taking out everything in the method and just having return "ok" and it still crashes.</p>
  
  <p>Does anyone have any suggestions as to why because I really cant see it at all.</p>
  
  <p>Thanks</p>
  
  <p>Steve</p>
  
  <p>The PostExecute code :- </p>
  
  <pre><code>protected void onPostExecute(String result) {
          if (pDialog.isShowing())
              pDialog.dismiss();
  
          if (result == "ok") {
              ((Globals) getApplication()).ClearCacheFile(((Globals) getApplication()).getActionCacheFileName());
          } else {
              if (result == "error") {
                  Toast.makeText(getApplicationContext(),
                          "Clocking Error. Try Again !!!", Toast.LENGTH_LONG)
                          .show();
              } else {
                  if (result == "conIssue") {
                      Toast.makeText(
                              getApplicationContext(),
                              "Server not connected. Data will be updated when connection will be available.",
                              Toast.LENGTH_LONG).show();
                  } else {
                      Toast.makeText(
                              getApplicationContext(),
                              "Clocking Error. Server connection problem !!!",
                              Toast.LENGTH_LONG).show();
                  }
              }
          }
      }
  </code></pre>
  
  <p>This is what appears in the logs at the exact point of the crash :-</p>
  
  <pre><code>08-28 09:19:28.271  22411-22411/com.pe_systems.unity.unityandroid E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: com.pe_systems.unity.unityandroid, PID: 22411
  java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{246c3ec6 V.E..... R......D 0,0-959,128} not attached to window manager
          at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:396)
          at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:322)
          at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:116)
          at android.app.Dialog.dismissDialog(Dialog.java:341)
          at android.app.Dialog.dismiss(Dialog.java:324)
          at com.pe_systems.unity.unityandroid.Clocking.ClockingActivity$ServerConnectionTask.onPostExecute(ClockingActivity.java:408)
          at com.pe_systems.unity.unityandroid.Clocking.ClockingActivity$ServerConnectionTask.onPostExecute(ClockingActivity.java:357)
          at android.os.AsyncTask.finish(AsyncTask.java:636)
          at android.os.AsyncTask.access$500(AsyncTask.java:177)
          at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5254)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  </code></pre>
  
  <p>08-28 09:19:28.272     546-3362/? W/ActivityManager﹕ Force finishing activity 1 com.pe_systems.unity.unityandroid/.Main.MainActivity
  08-28 09:19:28.348      546-603/? I/OpenGLRenderer﹕ Initialized EGL, version 1.4</p>
  
  <p>Code for ClearCaheFile :-</p>
  
  <pre><code>    public void ClearCacheFile(String fileName)
  {
      File key = new File(getExternalCacheDir(), fileName);
      try {
          FileWriter writeKey = new FileWriter(key);
  
          BufferedWriter out = new BufferedWriter(writeKey);
          out.write("");
          out.close();
  
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>