Skip to content Skip to sidebar Skip to footer

How To Start An Activity From An Alertdialog?

I created an AlertDialog : public class ConfirmChoixDownloadDialogView extends AlertDialog { private Activity activity; // this activity shows this Dialog private View co

Solution 1:

showDialog(this, "", newDialogInterface.OnClickListener() {
        @OverridepublicvoidonClick(DialogInterface dialog, int which) {
            Intenti=newIntent(getApplicationContext(), NextActivty.class);
            startActivity(i);
            finish();
        }
    });

Solution 2:

In your case maybe try using the context of the AlertDialog instead of the Activity calling it like this:

context.startActivity(i); instead of activity.startActivity(i)

Solution 3:

Ok , I found a tip to start the activity from the activity which opened the Dialog by implementing the onWindowFocusChanged method of the activity and setting a public static variable of the activity inside the OnDismissListener of the Dialog !

Post a Comment for "How To Start An Activity From An Alertdialog?"