I am using this alert dialog to pop-up a message saying that no Active internet connection is available.
I want to get back to the MainActivity when the user click’s OK but i can’t seem to get this going.
package com.xx.xx.xxhelper;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
public class AlertDialogManager {
public void showAlertDialog(Context context, String title, String message,
Boolean status) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(message);
if(status != null)
// Setting alert dialog icon
alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
// Showing Alert Message
alertDialog.show();
}
}
I added
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(AlertDialogManager.this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent);
}
});
But i get:
- The constructor Intent(AlertDialogManager, Class) is undefined
- The method startActivity(Intent) is undefined for the type new DialogInterface.OnClickListener(){}
any clues?
Pass in the
Activitycontext (to start activity when OK is clicked on the alert dialog) using something like the following: