0

In my application, I have a connection to a server and I want to transfer a file on it. So first, I have to select a file. I open a file browser with this code :

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
intent.setType("*/*");
startActivityForResult(intent, REQUEST_BROWSE_FILES);

The problem arrive if I have a disconnection during time I browse to find a file. If the connection is lost, I want to popup a message box saying : "Connection lost" then I want to close the file picker. How can I do something similar to that ?

In fact, when the disconnection occur, I don't know which activity is on top to show a message. Did I miss something, but it is annoying to need an activity to popup a dialog.

Thank you for your help.

1 Answers1

0

you cant directly close another activity from yours that you started from a file picker intent. I think you just need to wait for them to choose something and once you get the response back in OnActivityResult check if you disconnected and if you are just show a popup that you are disconnected

Tomer Shemesh
  • 10,278
  • 4
  • 21
  • 44
  • It is exactly what I did, but I consider that as a workaround. I wanted to close the popup as soon as I know that my connection is closed. But thanks for your answer !! – François Dubois Jul 03 '17 at 14:21