Close activity after clicking "Add" button in warning dialog in android

I have an activity called "A" that displays a list of items. The "Refresh" button displays a user dialogue (activity is displayed on the back) with a list of selected items. When the "Order" button is clicked inside the user dialog.

  • The user dialog disappears.
  • execution dialog is displayed (as the work of the order continues)
  • after the job is completed, the run dialog is executed.
  • Show the alert dialog box that says โ€œOrder Confirmedโ€
  • When I click the positive button in the warning dialog box, I want to close the activity that is in the back (i.e. operation A). To go to the main screen
  • How can I call the completion code inside the alertdialog positive Onclicklistener () button

Please help me solve this problem.

noData.setPositiveButton("Ok", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); 

How to add finish () after canceling alertDialog ()

+4
source share
3 answers

You will need something like this:

 noData.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Finish activity finish(); } }); 

Just adding finish () inside onClick should do the trick.

+12
source

See the code below (replace MyActivity with the name of your activity this code lives in):

 noData.setPositiveButton("Ok", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { MyActivity.this.finish(); } }); 

Adding this very important!

+4
source

The best option is to go with a handler. here is the link link http://www.tutorialforandroid.com/2009/01/using-handler-in-android.html

0
source

Source: https://habr.com/ru/post/1344737/


All Articles