0

I'm trying to open the document tree to allow the user to save some data in the location of their choice. Here's code:

public void OpenFilePicker(Uri uriToLoad, int theCode)
{
Intent aIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
aIntent.putExtra("android.content.extra.SHOW_ADVANCED", true);
aIntent.putExtra("android.content.extra.FANCY", true);
mActivity.startActivityForResult(aIntent, theCode);
}

...when this runs, it opens the document tree, allows me to select something, but then I just never get onActivityResult. It just locks up and after a couple seconds says the app is not responding.

What am I doing wrong here?

Edit: Additional info, this happens on devices with Android 11+ on it. 9 (the only lower version I have available) works fine. Is it a security issue?

Final Edit: Idiotic solution... although I "cleaned projec" to force a rebuild all early in the process, evidently "clean project" doesn't actually mean clean the project. By manually deleting the build directories and rebuilding, the problem went away. Something bad was baked into the build that wasn't getting deleted by the rookie move of selecting "clean project" to clean the project. Noted for all future mystery bugs.

KiraHoneybee
  • 495
  • 3
  • 12
  • You're calling `Activity`'s `startActivituForResult`, so you need to override `onActivityResult` for that activity. You probably overriding fragment's `onActivityResult` – Shlomi Katriel Apr 10 '22 at 14:04
  • @ShlomiKatriel No, the override is in my activity. It never gets there-- never even hits the logging statement that's the first line in the override. I updated the question-- this only happens in Android 11+ ... works fine before that. – KiraHoneybee Apr 10 '22 at 15:21
  • To my next theory then - activity is recreated (either by configuration change or "don't keep activities from developer options), but `mActivity` holds reference to the old activity. Please check if you get activity `onDestroy`, `onCreate` sequence after calling `startActivityForResult` and make sure "Don't keep activities" is turned off in developer options, then let me know – Shlomi Katriel Apr 10 '22 at 16:17
  • 1
    @ShlomiKatriel Well, here's one for the record books: CLEANING the project folder to do a rebuild all doesn't actually clean the whole project folder. But when I deleted the build intermediary directories and rebuilt it then, the problem went away. So it wasn't even a code issue it was some glitch baked into the build files that didn't get cleaned. I'm starting a petition to get "clean project folder" changed to "clean project folder mostly, sorta" – KiraHoneybee Apr 11 '22 at 11:57

0 Answers0