We’ll see an example of storing a string in this Intent object using a key. These key-value pairs are known as Extras in the sense we are talking about Intents. We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. * Creates an Intent object by giving the context and the class of next activity to be opened */ Intent intent = new Intent(this, NewActivity.class) //starting the activity startActivity(intent) Using putExtra() To start an activity we'll create an object of the intent and pass it to the startActivity() method. They are basically massage passed between components (Activities, Services, Broadcast receivers etc). As the name suggests Intents are intentions to perform something. We’ll start of with the basic concept of starting an activity from a current activity. We can achieve other solutions using the same idea. Instead, passing data from one activity to another and displaying related info is a better way. Creating multiple activities to display contents of same properties is not an ideal solution. Intents in android offers this convenient way to pass data between activities using Extras. Whenever you need data from an activity to be in another activity, you can pass data between then while starting the activities.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |