title: The App keeps restarting itself
body: <p>I am trying to pass an intent from the doInBackground method to the onLocationchanged method in the inner LocationListent of the MainActivity. I am facing the problem the appp keeps restarting, then freezing and the device restart itself.</p>
  
  <p>The routes varibale has these values [7,31]. </p>
  
  <p>The app works fine without intent (the added code which I commetted  //Like This//)</p>
  
  <p>I appreciate any help.</p>
  
  <p>Error:</p>
  
  <pre><code>05-17 21:19:12.553: E/ActivityThread(19497): Performing stop of activity that is not resumed: {com.bustracker/com.bustracker.MainActivity}
  05-17 21:19:12.553: E/ActivityThread(19497): java.lang.RuntimeException: Performing stop of activity that is not resumed: {com.bustracker/com.bustracker.MainActivity}
  05-17 21:19:12.553: E/ActivityThread(19497):    at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3822)
  05-17 21:19:12.553: E/ActivityThread(19497):    at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3910)
  05-17 21:19:12.553: E/ActivityThread(19497):    at android.app.ActivityThread.access$1200(ActivityThread.java:177)
  05-17 21:19:12.553: E/ActivityThread(19497):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
  05-17 21:19:12.553: E/ActivityThread(19497):    at android.os.Handler.dispatchMessage(Handler.java:102)
  05-17 21:19:12.553: E/ActivityThread(19497):    at android.os.Looper.loop(Looper.java:145)
  05-17 21:19:12.553: E/ActivityThread(19497):    at android.app.ActivityThread.main(ActivityThread.java:5944)
  05-17 21:19:12.553: E/ActivityThread(19497):    at java.lang.reflect.Method.invoke(Native Method)
  05-17 21:19:12.553: E/ActivityThread(19497):    at java.lang.reflect.Method.invoke(Method.java:372)
  05-17 21:19:12.553: E/ActivityThread(19497):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
  05-17 21:19:12.553: E/ActivityThread(19497):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
  </code></pre>
  
  <p>MainActivity:</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
         //I added "this" here//.
          LocationListener ll = new myLocationListener(this);
          lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, ll);
  
      }
        //Inner class in MainActivity
      class myLocationListener implements LocationListener {
          // I added here the bContext and the constructor//
          final Context bContext;
  
          public myLocationListener(Context context){
              bContext = context;
          }
  
          @Override
          public void onLocationChanged(Location location) {
  
                  PostData sender = new PostData();
                 // I added here the context  parameter.//
                  sender.post_data(jSONString, bContext);
                    //I added here this part to receive the intent from onPostExecute //
                  Bundle extra = getIntent().getExtras();
                  if (extras != null) {
                      ArrayList&lt;Integer&gt; c = extras
                              .getIntegerArrayList("stop_route");
                      for (int item : c) {
                          System.out.println("The Intent is not empty: "
                                  + item);
                      }
                  }  
  protected void onResume() {
  
      super.onResume();
  }
  
  @Override
  protected void onPause() {
      super.onPause();
  }             
          }
  </code></pre>
  
  <p>Some of the output in OnLocationChanged:</p>
  
  <pre><code>05-17 21:24:04.969: I/System.out(19497): The Intent is not empty: 7
  05-17 21:24:04.969: I/System.out(19497): The Intent is not empty: 31
  </code></pre>
  
  <p>.
    .
    . I am getting over 30 lines in one output? </p>
  
  <p>PostData class:</p>
  
  <pre><code>public class PostData {
      String jSONString;
  
      // Context mContext;
  
      public PostData() {
          super();
  
      }
  
      public String getjSONString() {
          return jSONString;
  
      }
  
      public void setjSONString(String jSONString) {
          this.jSONString = jSONString;
      }
  
      public void post_data(String jSONString, Context context) {
          this.jSONString = jSONString;
  
          new MyAsyncTask(context).execute(jSONString);
  
      }
  
      class MyAsyncTask extends AsyncTask&lt;String, Integer, Void&gt; {
          final Context mContext;
          ArrayList&lt;Integer&gt; routes = new ArrayList&lt;Integer&gt;();
  
  
          public MyAsyncTask(Context context) {
              mContext = context;
          }
  
  
          @Override
          protected Void doInBackground(String... params) {
              // TODO Auto-generated method stub
              BufferedReader reader = null;
  
  
              try {
                  System.out.println("The output of : doInBackground "
                          + params[0]);
  
                  URL myUrl = new URL(
                          "https://blabla.rhcloud.com/test");
                  HttpURLConnection conn = (HttpURLConnection) myUrl
                          .openConnection();
                  conn.setRequestMethod("POST");
                  conn.setDoOutput(true);
                  conn.setConnectTimeout(10000);
                  conn.setReadTimeout(10000);
                  conn.setRequestProperty("Content-Type", "application/json");
                  conn.connect();
  
                  // System.out.println("The output of getResponsecode: "
                  // + conn.getResponseCode());
                  // create data output stream
                  DataOutputStream wr = new DataOutputStream(
                          conn.getOutputStream());
                  // write to the output stream from the string
                  wr.writeBytes(params[0]);
  
                  wr.close();
  
                  StringBuilder sb = new StringBuilder();
                  reader = new BufferedReader(new InputStreamReader(
                          conn.getInputStream()));
                  String line;
  
                  while ((line = reader.readLine()) != null) {
                      sb.append(line + "\n");
  
                  }
  
                  Gson gson = new Gson();
                  StopsJSON data = gson.fromJson(sb.toString(), StopsJSON.class);
  
               routes = data.getRoutes();
  
  
                  System.out.println("The output of the StringBulder before "
                          + routes);
                  System.out.println("The output of the StringBulder: "
                          + sb.toString());
  
              } catch (IOException e) {
  
                  e.printStackTrace();
                  return null;
              } finally {
                  if (reader != null) {
                      try {
                          reader.close();
                          return null;
                      } catch (Exception e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }
                  }
              }
  
              return null;
  
          }
  
          @Override
          protected void onPostExecute(Void result) {
              // Intent with Conetxt of the Asyntask class and
              Intent intent = new Intent(mContext, MainActivity.class);
              intent.putExtra("stop_route", routes);
              mContext.startActivity(intent);
  
          }
  
      }
  
  }
  </code></pre>