In this part:
if (success == 1) { Intent i = new Intent(getApplicationContext(), MainActivity5.class ); startActivity(i); finish(); }
before you call finish() , you need to cancel the progress dialog. This does not quit, so the window leaks and throws an exception.
Use this code instead:
if (success == 1) { Intent i = new Intent(getApplicationContext(), MainActivity5.class ); startActivity(i); pDialog.dismiss(); finish(); }
Also run a new action with onPostExecute() , not doInBackground() . Use the flag to check your event for success and start a new action in onPostExecute() as follows:
@Override protected String doInBackground(String...args) { //... if (success == 1) { successFlag=true; } //... } @Override protected void onPostExecute(String file_url) { if(successFlag=true) { Intent i = new Intent(getApplicationContext(), MainActivity5.class ); startActivity(i); pDialog.dismiss(); finish(); } }
source share