Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an event when user cancels intent chooser?

In my android application I want the user to choose, which other application should be used to display a certain image if there are more than one possible apps. Therefore I got following code:

final Intent intent = new Intent(Intent.ACTION_VIEW)
                       .setDataAndType(uri, IMAGE_MIME_TYPE)
                       .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY);

 context.startActivity(intent);

As intented an app chooser is displayed.

Right before I call startActivity I open a ProgressDialog, which I want to close when for example the user cancels the app chooser via back button. What is the best way to identify that the app chooser was canceled? In other words - where should I close my ProgressDialog?

like image 250
c7n Avatar asked Jul 05 '16 08:07

c7n


Video Answer


1 Answers

Start an activity like this:

 context.startActivityForResult(viewIntent, <int flag>);

Then in onActivityResult():

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == <int flag>) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            // The user pressed ok
        }else{
            // The user pressed cancel 
        }
    }
}
like image 170
Jignesh Ansodariya Avatar answered Sep 23 '22 00:09

Jignesh Ansodariya