Android Intents

From bibbleWiki
Revision as of 02:16, 27 January 2021 by Iwiseman (talk | contribs) (Implicit)
Jump to navigation Jump to search

Introduction

Intents

There are two types of intents

  • Explicit
  • Implicit

Explicit

We can start an explicit intent with

val intent = Intent(this.MyActivityClass::class.java_
startActivity(intent)

Implicit

No destination intent is defined. The user will be prompted for which application to use. Not the use of the apply operator.

val intent = Intent().apply {
    action = Intent.ACTION_SEND
    putExtra(Intent.EXTRA_TEXT,"Hello World")
    type = "text/plain"
}
startActivity(intent)


Quite nice compared with the code without the apply.

val intent = Intent()
intent.action = Intent.ACTION_SEND
intent.putExtra(Intent.EXTRA_TEXT,"Hello World")
intent.type = "text/plain"
startActivity(intent)