I am creating an app which requires an alert dialog to pop up from a class that is not an activity. I tried creating one with the help of a AlertDialog builder and passed the context in, but the app stops working whenever I try to show the alert. When I used the same method to create an AlertDialog in the main activity it worked, but if I do that, it will not pop up at the time I want it to. Is there anyway I can make an AlertDialog from a class that is not an activity? Or I can access the activity reference from the class so that I can use it to create the alert?
Please note that the class is created as a result of a service, and not using the constructer directly from the main activity, so I cannot pass the main activity reference through the constructor. Currently I have put a notification in place of the alert, but I would much rather have an alert than a notification.