0

I am new to AsyncTask:

I want that whenever the user gets 'login success' the user will get alert with Ok, and when this Ok is clicked then the user should go to Activity2 screen.

I am unable to do this. Please help. Below is the code:

@Override
protected void onPostExecute(String result) {
   alertDialog.setMessage(result);

   if(result.equals("login success")) {
      alertDialog.setButton("OK", new DialogInterface.OnClickListener() {

         @Override
         public void onClick(DialogInterface dialog, int which) {
            setContentView(R.layout.activity_main2);
         }
      });
   } else {
   }

   alertDialog.show();
}
sharonooo
  • 684
  • 3
  • 8
  • 25
  • Instead of setContentView(R.layout.activity_main2) , call Activity2 using Intent – Parul Oct 04 '18 at 09:36
  • 2
    Possible duplicate of [How to open a second activity on click of button in android app](https://stackoverflow.com/questions/13194081/how-to-open-a-second-activity-on-click-of-button-in-android-app) – Mohamed Mohaideen AH Oct 04 '18 at 09:44

1 Answers1

0
Write below code, when user taps on onClick 

@Override
public void onClick(DialogInterface dialog, int which) {

Intent intent = new Intent(MainActivity.this,Activity2.class);
startActivity(intent);
     }
   });
 }
Chetan Ansel
  • 398
  • 2
  • 20