would it be possible, to start activity for result...
# android
p
would it be possible, to start activity for result (e.g. select file), if you only have context. I have a wild idea of making interactor/usecase that does that. Any ideas?
Copy code
class SelectFileUseCase @Inject constructor(
    @ApplicationContext private val context: Context
) {
    operator fun invoke(): Uri {
        val intent = Intent().apply {
            type = "file/*"
            action = Intent.ACTION_GET_CONTENT
            addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        }

        context.startActivity(intent)
        
        // how to get result??
        context.registerReceiver(receiver, filter) // maybe?
    }
}
a
Nope, an activity started for result needs an activity to return the result to
p
bummer. Thanks!
i
That being said, you absolutely can push all of the intent handling out into your own, separately testable class if you're using the
ActivityResultRegistry
class and its methods: https://developer.android.com/training/basics/intents/result#separate
(you just need to hook it up to an activity / its
ActivityResultRegistry
at some point)