Intent
Use Intent to communicate between Activity, Service, and BroadReceive
Intent object properties:
- 2. Data
- 4. Extras
- name
Component name:
Set the Intnet component object name Determine the unique activity via Package name + Class name
Similar to Component in Spring, setting or starting specific components according to component name
setComponent(componentName)
Intnet intnet = new Intnet(); ComponentName componentName = new ComponentName("",""); (componentName); startActivity(intnet)
Action & Data
Next action and corresponding data
Action attributes and Data attributes
The first step is to set the permissions to enable phone and email in manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:andro package=""> <uses-permission android:name=".CALL_PHONE"></uses-permission> <uses-permission android:name=".SEND_SMS"></uses-permission> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="" /> <category android:name="" /> </intent-filter> </activity> <!-- CustomizeActivity Need to be inmainifests Configuration Statement --> </application> </manifest>
package ; import ; import ; import ; import ; import ; import ; /** * Function: Action Data Share Click on Call and Send Email Buttons to jump to the system Call and Email Interface * * * */ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_main); ImageButton phoneButton = findViewById(.imageButton_phone); ImageButton smsButton = findViewById(.imageButton_sms); (l); (l); } // Define the listener object method common l = new () { @Override public void onClick(View view) { Intent intent = new Intent(); ImageButton imageButton = (ImageButton) view; switch (()){ case .imageButton_phone: // Call the dial panel (intent.ACTION_DIAL); (("tel: 043184978981")); startActivity(intent); break; case .imageButton_sms: (intent.ACTION_SENDTO); (("smsto: 5554")); // Set text message content ("sms_body", "welcome to Android"); startActivity(intent); break; } } }; }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:andro xmlns:tools="/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Technical Support: Jilin Tomorrow Technology Co., Ltd." android:layout_marginTop="20dp"/>
<TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Website:" android:layout_marginTop="10dp" android:layout_below="@+id/text1"/> <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Company Email: mingrisoft@" android:layout_marginTop="10dp" android:layout_below="@+id/text2"/> <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Technical Service Hotline: 0431-84978981" android:layout_marginTop="10dp" android:layout_below="@+id/text3"/> <ImageButton android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/phone" android:layout_below="@+id/text4" android:layout_marginTop="30dp" android:background="#0000" android:scaleType="fitXY" /> <ImageButton android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/imageButton_phone" android:layout_below="@+id/text4" android:layout_marginTop="30dp" android:layout_marginLeft="30dp" android:background="#0000" android:scaleType="fitXY" android:src="@drawable/sms"/> </RelativeLayout>
Action & Category
Category attribute classifies the activity and classifies the corresponding activity
package ; import ; import ; import ; import ; import ; import ; import ; /** * Function: Action Data Share Click on Call and Send Email Buttons to jump to the system Call and Email Interface * * * */ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_main); //Set full screen display getWindow().setFlags(.FLAG_FULLSCREEN, .FLAG_FULLSCREEN); ImageButton imageButton= (ImageButton) findViewById(.imageButton1); //Get ImageView component //Set the click event listener for the ImageView component (new (){ @Override public void onClick(View view) { Intent intent = new Intent(); (intent.ACTION_MAIN); (intent.CATEGORY_HOME); } }); } }
Flags attributes
Function: Let the current activity not be retained in the history stack. When the user leaves the app and enters again, it is not the current activity interface. Go to the main interface of the system.
Intnet Types
Show Intnet:
Create an Intnet object -> Target component -> Start the Target component:
Intnet intnet = new Intnet(, CallActivityObject)
Implicit Intnet object creation does not specify the target component. Through action, category, and data, the Android system automatically matches the target component.
Difference: Display Directly specify the target component name, which is often used to pass information inside the application.
Implicit Intnet: The activated target component cannot be defined with component names, and is often used to pass information between different applications.
Intent Filter
Activity A ActivityB selected by category + action + data is the target ActivityB selected by Filter condition brushing.
Configure in the file
<intent-filter> <category></category> <action></action> </intnet-filter> <activity android:name=".MainActivity"> <intent-filter> <action android:name=""/> <category android:name=""/> </intent-filter> </activity>
When opening the picture, use different apps to draw pictures or click
Completed via implicit Intnet
This is the end of this article about Android Intent Communication. For more information about Android Intent Communication, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!