issue with ActivityResultContracts.CreateDocument?

586 Views Asked by At

MainActivity.kt

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val save = registerForActivityResult(ActivityResultContracts.CreateDocument()) {
            Log.d("<debug>", "uri: $it")
        }

        findViewById<Button>(R.id.button).setOnClickListener {
            save.launch("file")
        }
    }
}
  1. Navigating to the Download folder, only irrelevant files

enter image description here

  1. Using the code above, saving 1 file

enter image description here

  1. If I re-run the code to save a file again

enter image description here

  1. Navigating to the Download folder

enter image description here

Basically, whenever I delete the file in Download and re-run the code, it displays all the previously created files, even though there's only 1 in there.

note: the issue persists even if I delete then reinstall the app or power cycle the device (pixel 3, pixel 6 both on android 12)

0

There are 0 best solutions below