Appendix A. Leftovers: The Top Ten Things (we didnât cover)
Even after all that, thereâs still a little more.
There are just a few more things we think you need to know. We wouldnât feel right about ignoring them, and we really wanted to give you a book youâd be able to lift without extensive training at the local gym. Before you put down the book, read through these tidbits.
1. Sharing data with other apps
If you want to share simple data with another app, you can do so with an Intent
. You can think of an Intent
as an âintent to do something.â Itâs a type of message that lets you send data to another objectâsuch as an activityâat runtime.
Sharing data with Androidâs intent resolver
If you want to pass text to another activity, you can do so using code like this:
val sendIntent: Intent = Intent().apply { action = Intent.ACTION_SEND putExtra(Intent.EXTRA_TEXT, "This is some text.") type = "text/plain" } startActivity(sendIntent)
The code first creates an Intent
named sendIntent
. It uses the type
property to specify the type of data thatâs being sent (in this case plain text), and uses putExtra()
to attach the data (here, itâs some text).
The action
property tells Android which types of activity can receive the intent. Here, itâs set using:
action ...
Get Head First Android Development, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.