Android Kotlin – Explicit and Implicit intents

, <span>Android Kotlin – Explicit and Implicit intents</span>, KandZ

More detailed information about intents you can find here and here.

Explicit intents open a specific application. You need to provide the package name or the fully qualified class name for the target application/activity.

Implicit intents open an application but you need to declare an action (ACTION_SEND, ACTION_SENDTO, ACTION_VIEW etc).

 

Explicit intent:

val intent = Intent(this, SecondActivity::class.java)
startActivity(intent)

#if you want to send information then add before the 
# startActivity
intent.putExtra("info", infoString)

Implicit intent:

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

#if you want to show the chooser dialog
val dialog:Intent = Intent.createChooser(intent, titleTextForTheChooser)

#if you want to be sure that there is an activity to receive this intent
if (intent.resolveActivity(packageManager) != null {
    startActivity(intent)
}

 

36970cookie-checkAndroid Kotlin – Explicit and Implicit intentsAndroid Kotlin – Explicit and Implicit intents

Related posts