krrakesh16
krrakesh16

Reputation: 217

Dismiss a popup from another activity

I am writing an application which is having an activity and I am launching a pop up ( pop up I have implemented in another class which is not an activity). In my main activity I have code to display the popup when there is an event. I am successfully able to do that. But I need to cancel the popup when I get another event. ( I will get this event only in the main activity). How can I finish the popup from the main activity when I receive the event?

Upvotes: 1

Views: 1133

Answers (3)

Aditya Nikhade
Aditya Nikhade

Reputation: 1371

final AlertDialog.Builder aBuilder;

//constructor(Context c){//mContext = c;}

public void showMessage(final String title, final String s) { 

        aBuilder = new AlertDialog.Builder(mContext); 
        aBuilder.setTitle(title); 
        aBuilder.setIcon(R.drawable.ic_launcher); 
        // aBuilder.setIcon(R.drawable.icon); 
        aBuilder.setMessage(s);
    }

public void dismissMessage() { 
        aBuilder.dismiss();
    }

Upvotes: 0

Visa
Visa

Reputation: 111

If this pop up is a dialog you can do it with

dialog.cancel();

Upvotes: 1

Aditya Nikhade
Aditya Nikhade

Reputation: 1371

create a public method in the class where you have created the popUP(dialog) and write inside it as

public void dismissDialog(){
    dialog.dismiss();
}

then whenever you want to remove the dialog call this method...

Upvotes: 2

Related Questions