Achilles Achilles - 4 months ago 11x
Android Question

Single alert dialog for entire application

I have to display many error messages and alert dialogues in my application.
I do not want to use Toast but i prefer to use ALertDialog.

Instead of creating a new alert dialog in every activity , how do i create and maintain one alert dialog an just change the error message string in it?

Whatever activity I am in,I must be able to access the alert dialog instance and show and dismiss it.

How can i achieve this ?
Kindly give me some lead on this.


make one class and paste this function...(may be

public static void alertDialogShow(Context context, String message)
            final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() 
                public void onClick(DialogInterface dialog, int which) 

and call this by writing..

Utils.alertDialogShow(YourActivity.this,"Your Error Message")