Skip to content

Instantly share code, notes, and snippets.

@mochadwi

mochadwi/README.md

Last active Mar 20, 2020
Embed
What would you like to do?
Passing extras with intent while using intent with action ACTION_GET_CONTENT

Original answer from StackOverflow:

  1. setResult(RESULT_OK, yourIntentWithExtras), click here for more details

Usage:

01. MainActivity.kt
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.putExtra("viewId", myViewIdParam)

intent.setType("image/*")

context.setIntent(intent)
context.startActivityForResult(intent, REQUEST_IMAGE_PICK)
02. DetailActivity.kt
val resultIntent = intent

resultIntent.putExtra("viewId", intent.getIntExtra("viewId", -1));

setResult(RESULT_OK, resultIntent);
finish();
03. MainActivity.kt (Receive your data to check activity intent and data intent
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_IMAGE_PICK && data != null) {
            val viewId = data.getIntExtra("viewId", intent.getIntExtra("viewId", -1))
            // todo your stuff here
        }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment