intent two ways to find a target component:
Explicit Intent: implemented by specifying the name of the intent component, which is typically implemented within the same application, with the knowledge of the target component name.
Implicit intent: implemented by the intent filter, which is generally used for different applications without explicitly stating the name of the target component.
First, display intent:
The complete process of creating an activity:
1. create a class manually to inherit from the activity:
Public class Myaty extends Activity
2. Let it bind a view:
public class Myaty extends Activity {
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.myaty);
}
}
3, Androidmainfest.xml file for intent configuration:
<activity android:name= ". Myaty "/> <!--<activity android:name=" Com.w.learnintent.myaty "/>-->
4, start the function code:
activity_main.xml file:<button android:text= "Start myaty" android:id= "@+id/btnstartmyaty"/>
In the Mainactivity.java file:
Findviewbyid (R.id.btnstartmyaty). Setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
StartActivity (New Intent (Mainactivity.this,myaty.class)); Show intent
}
Second, implicit intent:
1. androidmainfest.xml file for intent configuration:
<activity android:name= ". Myaty ">
<intent-filter>
<category android:name= "Android.intent.category.DEFAULT"/>
<action android:name= "Com.w.learnintent.intent.action.myaty"/>
</intent-filter>
</activity>
2. Create a string action in the Activity--myaty.java that is started:
public static final String ACTION = "Com.w.learnintent.intent.action.myaty";
3, start the function code:
StartActivity (New Intent (myaty.action)); Implicit intent
Iii. between different applications (implicit intent):
1. Create another program by creating a new module on the basis of the original project.
2, the original project androidmainfest.xml file for intent configuration:
<activity android:name= ". Myaty "android:exported=" false "> <!--android:exported: Whether the service can be called or interacted with by other application components--
<intent-filter>
<category android:name= "Android.intent.category.DEFAULT"/>
<action android:name= "Com.w.learnintent.intent.action.myaty"/>
</intent-filter>
</activity>
3. In the Mainactivity.java file of the new project:
Findviewbyid (R.id.btnstartmyaty). Setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
try {
StartActivity (New Intent ("Com.w.learnintent.intent.action.myaty"));
}catch (Exception e) {
Toast.maketext (Mainactivity.this, "Unable to start the specified activity", Toast.length_short). Show (); Toast.length_short short time rendering
}
}
Concept and application of intent in Android (i)--show intent and implicit intent