title: How to finish Activity from AsyncTask class in android?
body: <p>I have an activity with a hamburger menu. When I click on the hamburger menu logout enty, it will call an <code>AsyncTask</code>. After the API was called, if the statuscode indicates success then I need to call loginactivity. Up to here it works fine, but my problem is when I press the back button in login then it goes back to the previous screen. How to fix this? How do I finish activity in AsyncTask?</p>
  
  <pre><code>public class LandingActivityNew extends AppCompatActivity {
     mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem menuItem) {
              drawerLayout.closeDrawers();
              int id = menuItem.getItemId();
              switch (id){
                  case R.id.navItemSettings:
                      Intent iSettings = new Intent(LandingActivityNew.this,SettingsActivity.class);
                      startActivity(iSettings);
                      finish();
                      break;
                  case R.id.navItemTC:
                     // Toast.makeText(LandingActivityNew.this, "Settings", Toast.LENGTH_LONG).show();
                      Intent iTerms = new Intent(LandingActivityNew.this,TermsConditions.class);
                      startActivity(iTerms);
                      break;
                  case R.id.navItemPrivacy:
                      //Toast.makeText(LandingActivityNew.this, "Privacy", Toast.LENGTH_LONG).show();
                      Intent iPrivacy = new Intent(LandingActivityNew.this,ConsentActivity.class);
                      startActivity(iPrivacy);
                      break;
                  case R.id.navItemReportProblem:
                      Toast.makeText(LandingActivityNew.this, "Report a Problem", Toast.LENGTH_LONG).show();
                      break;
                  case R.id.navItemFAQ:
                      Toast.makeText(LandingActivityNew.this, "FAQ", Toast.LENGTH_LONG).show();
                      break;
                  case R.id.navItemShare:
                      Toast.makeText(LandingActivityNew.this, "Share", Toast.LENGTH_LONG).show();
                      break;
                  case R.id.navItemLogout:
                      new LogoutAsyncTask(LandingActivityNew.this).execute();
                      break;
  
              }
              return false;
          }
  
      });
  
  }
  </code></pre>
  
  <p>AsyncTask class like this...</p>
  
  <pre><code>public class LogoutAsyncTask extends AsyncTask&lt;String,String,String&gt; {
     Context context;  
     public LogoutAsyncTask(Context context){
      this.context = context;
      }
     @Override
  protected void onPreExecute() {}
  @Override
  protected String doInBackground(String... params) {}
     @Override
  protected void onPostExecute(String file_url) {
      if (pDialog.isShowing()) {
          pDialog.dismiss();
      }
      int appStatusCode = getLogoutResponse.getAppStatusCode();
      if (appStatusCode == Constants.APP_STATUS_CODE_SUCCESS) {
          ***Intent logout=new Intent(context,LoginActivity.class);
          context.startActivity(logout);
          ((Activity)context).finish();***
      } else {
          ExceptionMessages.showAlertDialog(context, "Unable to Logout", getLogoutResponse.getMessages().get(0), true);
      }
  }
   }
  </code></pre>
  
  <p>in onPost() I need to finish the activity call, how to do that?</p>