user749873
user749873

Reputation: 43

Code to Show Toast message after dismiss the progress dialog in android?

I have situation where I want to toast message to user after dismissing the Progress dialog. how can i do this all code is executed only the Toast.showMessage(,"",,).show is not working. Below is my code please look into this and give me the suggestion.

if (common.split.equals("failure")) {

                try {

                    if (this.pd.isShowing()) {
                        this.pd.dismiss();
                    }


                    Toast.makeText(getApplicationContext(), "No data found",
                            Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    // TODO: handle exception
                }

            }

Upvotes: 0

Views: 2270

Answers (2)

MysticMagicϡ
MysticMagicϡ

Reputation: 28823

You can try this code:

this.pd.setOnDismissListener(new OnDismissListener() {

    @Override
    public void onDismiss(DialogInterface arg0) {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), "Text of Toast", Toast.LENGTH_SHORT).show();
    }
});

Upvotes: 2

Ion Aalbers
Ion Aalbers

Reputation: 8030

First thing: Never catch all exceptions with :

} catch (Exception e) {
    // TODO: handle exception
}

Log the exception there with e.getMessage() or e.printStackTrace(), it is possible that it crashes when you are dismissing the dialog, and because you aren't logging it you won't know for sure if the problem is at the toast.

And specify with exception you want to catch like:

catch (IOException e)

Else you can catch nullpointer exceptions, which most of the time are programmer errors :)

Upvotes: 2

Related Questions