Android Intents: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
Created page with "=Introduction= ==Intents== There are two types of intents *Explicit *Implicit ==Explicit== We can start an explicit intent with <syntaxhighlight lang="kotlin"> val intent = In..."
 
Line 20: Line 20:
startActivity(intent)
startActivity(intent)
</syntaxhighlight>
</syntaxhighlight>
<br>
Quite nice compared with the code without the apply.
Quite nice compared with the code without the apply.
<syntaxhighlight lang="kotlin">
<syntaxhighlight lang="kotlin">

Revision as of 02:16, 27 January 2021

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)