Answer the question
In order to leave comments, you need to log in
How to call the main activity from AlertDialog?
My collapsed application calls AlertDialog. It has two buttons OK and Cancel. With Cancel, we simply close the AlertDialog, but with the OK button, you need to display the main application activity or simply bring the application to the foreground. How to do it?
Answer the question
In order to leave comments, you need to log in
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("Cообщение")
.setMessage("Приложение свернули")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(MainActivity.this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
alert.show();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question