I am developing an application which will display an Alertdialog box when it gets an event. Currently the alert will come only in that particular activity. I need to get this alert on all the screens ( eg. home screen, message screen, etc )except I am in a call.
Please provide a solution for this.
Create one class and make one constructor in it . Pass the Activity context to constructor. Now make one function and put code of Alert Dialog in it.
Now whenever you want that dialog you can just call it with crate object of that class and call function of alert Dialog.
You can create a AlartMessage.java file in util package where put this static method.
In
Utils
class, make this method :For example, in class in which you need to show alert :
Create some
Utils
class with static method that will takesContext
as an argument and builds whole dialog.Edit:
And call it in every place you need: