The Parcelable interface adds methods to all classes you want to be able to transfer between activities. What should you do when you want to pass an object and its data from one activity to the other? You use the parcelableinterface This works well for basic data types such as string, bool, and Integer but doesn’t work for objects. getStringExtra ( "name" ) Integer age = intent. putExtra ( "age", 26 ) //inside second activity Intent intent = getIntent ( ) String suburb = intent. The idea is to make the process of passing different types of data easy as: //Inside first activity Intent intent = new Intent ( MainActivity. Part of the process is sending data between activities and you do that via the putExtra and getExtra methods of our intent object. This lets you launch an activity and optionally return later (If you’re new to intents there’s a good resource in the Google dev docs that explains the process) To move from one activity to another you use the intent class to connect them together. For example a primary activity with a list of elements and a corresponding secondary activity to show the details of these elements. An Android app typically consists of more than one activity that need to pass data between each other.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |