getLastName ())Ī faster and more reliable approach is to use Parcelable as a replacement for Serializable. getSerializableExtra ( "user" ) as User ? val tvUser = findViewById ( R. getSerializableExtra ( "user" ) TextView tvUser = ( TextView ) findViewById ( R. putExtra ( "user", u ) startActivity ( i )Īnd access the user data in the launched intent with getSerializableExtra: // SecondActivity.java User u = ( User ) getIntent (). putExtra ( "user", u ) startActivity ( i ) val u = User ( "John", "Smith", 45 ) val i = Intent ( this, SecondActivity :: class. User u = new User ( "John", "Smith", 45 ) Intent i = new Intent ( ActivityOne. Then you can pass arbitrary user objects into an intent as an extra: Using an intent is as simple as constructing the Intent with the correct parameters and then invoking that intent using the startActivity method: // ActivityOne.java public void launchComposeView () For example, if you the user presses the "compose" button and you want to bring up an activity for them to compose a message, you would launch that second activity using an explicit intent. Explicit IntentsĪn "explicit" intent is used to launch other activities within your application. The Intent object itself is a class that represents a particular "request" including the topic of the request and any request "parameters" which are called the Bundle.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |