title: Tried everything but android finish(); activity not working
body: <p>We tried everything to finish a particular activity but failed to do so. The Code runs without any error or warning just cant finish the activity. We tried every solutions in stackoverflow along with other forums. Need a solution with explanation. </p>
  
  <p><a href="https://stackoverflow.com/questions/12217871/android-finish-activity-not-working">Android finish() Activity Not working</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18131466/android-finishing-activity-not-working">Android finishing activity not working</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5376730/android-finish-activity-context">android finish activity context</a></p>
  
  <pre><code>public void HttpSmsRequest(final String Phone){
          final ProgressDialog pDialog = new ProgressDialog(this);
          pDialog.setMessage("Loading...";
          pDialog.show();
  
  
  
          Map&lt;String, String&gt; jsonParams = new HashMap&lt;String, String&gt;();
          // jsonParams.put("param1", youParameter);
          jsonParams.put("Phone", Phone);
  
  
          //jsonParams.put("rememberMe", "true";
  
          JsonObjectRequest myRequest = new JsonObjectRequest(
                  Request.Method.POST,
                  AppGlobal.host+"PhoneVerification/sendSms",
                  new JSONObject(jsonParams),
  
                  new Response.Listener&lt;JSONObject&gt;() {
                      @Override
                      public void onResponse(JSONObject response) {
  
                          try
                          {
                              Log.v("Success", "success: " + response.toString());
                              //MessageBox.Show(ProfileInfoActivity.this, "Response: " + response.toString());
                              pDialog.dismiss();
                              JSONObject obj=new JSONObject(response.toString());
                            //  String ID=obj.getString("ID";
                              String Flag=obj.getString("Flag";
                              String Message=obj.getString("Message";
  
  
  
                             // Context context = getApplicationContext();
                             //
                            ///  appPrefs.setUserIdentity(Integer.parseInt(ID));
  
  
  
                              if(Boolean.parseBoolean(Flag))
                              {
                                  Intent intent=new Intent(PhoneVerificationActivity.this,ConfirmSms.class);
                                  intent.putExtra("PhoneNumber", Phone);
                                  //intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY);
                                  startActivity(intent);
                                  finish();
                                  return;
                                  //finishActivity(Activity.RESULT_OK);
  
                              }
                          }
                          catch (Exception ex)
                          {
                              MessageBox.Show(context, ex.getMessage());
  
                          }
  
                          // verificationSuccess(response);
                      }
                  },
                  new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          //Log.v("Success", "Error: " + error.networkResponse.statusCode);
                          if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                              MessageBox.Show(PhoneVerificationActivity.this, "Error: " + error.toString());
                              AppController.getInstance().getRequestQueue().cancelAll("tag_json_obj";
                          }
  
  
                          pDialog.dismiss();
  
                          //verificationFailed(error);
                      }
                  }) {
  
              @Override
              public Map&lt;String, String&gt; getHeaders() throws AuthFailureError {
  
                  Map headers = new HashMap();
                  if (!Preference.getInstance().getCookie().equals("")
                      headers.put("Cookie", Preference.getInstance().getCookie());
                  return headers;
              }
  
  /*@Override
  protected Response&lt;JSONObject&gt; parseNetworkResponse(NetworkResponse response) {
  
  Map headers = response.headers;
  String cookie = headers.get("Set-Cookie".toString();
  Preference.getInstance().saveCookie(cookie);
  //  MyApp.get().checkSessionCookie(response.headers);
  Log.v("Success", "Response"+response.headers.toString());
  return super.parseNetworkResponse(response);
  }*/
          };
          AppController.getInstance().addToRequestQueue(myRequest, "tag_json_obj";
  
      }
  </code></pre>