Skip to content

Instantly share code, notes, and snippets.

@douglasiacovelli
Created December 14, 2017 20:55
Show Gist options
  • Save douglasiacovelli/2de02905e8520f94476b115f2401d390 to your computer and use it in GitHub Desktop.
Save douglasiacovelli/2de02905e8520f94476b115f2401d390 to your computer and use it in GitHub Desktop.
class FormActivity: AppCompatActivity {
onCreate(...){...}
fun sendFormAndGoBack(name: String) {
// if you want to send any type of data back, such as an object, string, int etc
// you have to create an intent and use this bit of code
// otherwise you can just use setResult(Activity.RESULT_OK) and finish()
val resultIntent = Intent()
resultIntent.putExtra(INPUT_NAME, name)
setResult(Activity.RESULT_OK, resultIntent)
finish()
}
companion object {
@JvmField
val INPUT_NAME = "com.example.app.INPUT_NAME" //this is basically a static field in java that can be accessed from other classes
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment