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. Initiate a call for the user to a given numberĪs you can see, the Intent is a core part of user flows in Android development.Take the user to the camera to have them take a picture.Take the user to a particular URL within the Android web browser.Take the user to another screen (activity) within your application.A few key tasks that an intent might be used for within your apps: Think of an intent as a way for an Activity to communicate with the outside Android world. An intent is a message that can be thought of as a request that is given to either an activity within your own app, an external application, or a built-in Android service. Here is the code: package is a powerful concept within the Android universe. MainActivity.java:30 is line " String ten_bai_hat = listView.getItemAtPosition(position).toString() " ' ()' on a null objectĪt $1.onItemClick(MainActivity.java:30)) Open logcat, there is an error like this: I made MainActivity, BaiHat class and SecondActivity for getting data from the MainActivity. I have a problem when passing data from the main activity to another activity using Intents.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |