Intent the first usage is to use it to jump between activities
Create a new secondactivity activity and create a new second_layout for it. The XML layout file also creates a button with the name 2. Then register in Androidmanifest.xml.
Next, rewrite the button click Time in Firstacitivity
button Click events First create a new button listener, and then override the OnClick method in the listener.
The OnClick method is intent how to display the jump activity, that is, explicitly specify which activity to jump to. Create a new intent object that completes the active jump with the StartActivity method after the purpose is defined.
This will jump to the secongactivity activity when we click the button 1 in the firstactivity activity.
Intent there is also a way to jump activity, that is, "implicit jump", or the use of implicit intent.
We first set the secondactivity activity in the Androidmanifest.xml file, that is, set what kind of implicit intent it can be.
Secondactivity This intent is only possible if <action> and <category> can match the action and category specified in intent.
Where <category> set the "Android.intent.category.DEFAULT" This is the default category, that is, if the intent does not restrict the category conditions, it will automatically use this limit
Modify the onclick () in firstactivity
Run Discovery Click Button 1 to jump to the secondactivity activity, because the action is matched, and the category that is not set is automatically set to the default, which is also matched.
If you want to set the category, you only need to call intent's addcategory () method.
Of course, you have to set an activity to match the category, or it will be an error. We still set up secondactivity this activity
It can be found that the program runs correctly and still matches the activity on secondactivity. This indicates that an activity is capable of having multiple category attributes.
Learning ' The first line of code ' 2
Related uses of intent in Android