当前位置:网站首页>Andorid development III (intent)
Andorid development III (intent)
2022-07-28 10:41:00 【Upper back left love】
Intent
take Activity 、Serivce 、 BroadReceive Communication between Use Intent
- Intent Object properties :
- 1.Action, 2. Data 3.Category 4. Extras 5.Flags 6.Component name
- Component name:
Set up Intnet Component object name adopt Package name + Class name Determine the only one activity
similar Spring in Component according to component name Set or start specific components
- setComponent(componentName)
Intnet intnet = new Intnet();
ComponentName componentName = new ComponentName("com.example","com.example.DetailActivity");
intnet.setComponent(componentName);
startActivity(intnet)
- Action & Data
Next action and Corresponding data
Action Properties and Data attribute
The first step is manifest Set the permission to open phone and email
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.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="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Customize Activity Need to be in mainifests Configuration statement -->
</application>
</manifest>
package com.example.myapplication;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import androidx.appcompat.app.AppCompatActivity;
/** * function : Action Data share Click to make a call and Send mail button Conduct Jump system Make a phone call And email interface * * * */
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageButton phoneButton = findViewById(R.id.imageButton_phone);
ImageButton smsButton = findViewById(R.id.imageButton_sms);
phoneButton.setOnClickListener(l);
smsButton.setOnClickListener(l);
}
// Define listener objects Methods share
View.OnClickListener l = new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
ImageButton imageButton = (ImageButton) view;
switch (imageButton.getId()){
case R.id.imageButton_phone:
// Call the dial panel
intent.setAction(intent.ACTION_DIAL);
intent.setData(Uri.parse("tel: 043184978981"));
startActivity(intent);
break;
case R.id.imageButton_sms:
intent.setAction(intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto: 5554"));
// Set SMS content
intent.putExtra("sms_body", "welcome to Android");
startActivity(intent);
break;
}
}
};
}
``<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/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:id="@+id/text1"
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:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" website :http://www.mingrisoft.com"
android:layout_marginTop="10dp"
android:layout_below="@+id/text1"/>
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Enterprise mailbox :[email protected]"
android:layout_marginTop="10dp"
android:layout_below="@+id/text2"/>
<TextView
android:id="@+id/text4"
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:id="@+id/imageButton_phone"
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:id="@+id/imageButton_sms"
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 take Activity To classify , To the corresponding Activity To classify
package com.example.myapplication;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageButton;
import androidx.appcompat.app.AppCompatActivity;
/**
* function : Action Data share Click to make a call and Send mail button Conduct Jump system Make a phone call And email interface
*
*
* */
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set the full screen display
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
ImageButton imageButton= (ImageButton) findViewById(R.id.imageButton1); // obtain ImageView Components
// by ImageView Component settings click event listener
imageButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction(intent.ACTION_MAIN);
intent.addCategory(intent.CATEGORY_HOME);
}
});
}
}
- Flags attribute
effect : Let the current activity Not in the history stack , When the user leaves app When entering again Not now Activity Interface Go to the main interface of the system
Intnet species
- Show Intnet:
establish Intnet object -> Target component -> start-up Target component :
Intnet intnet = new Intnet(MainActivity.this, call Activity object )
- Implicit Intnet
Creating objects does not specify Target component , adopt action , category , data Give Way Android The system automatically matches the target component
difference : Show Directly specify the name of the target component , It is often used to transfer information inside applications
Implicit Intnet: The activated target component will not be defined with the component name , It is often used to transfer information between different applications
Intent Filter
Activity A adopt category + action + data As Filter The conditions are selected ActivityB Is the target Activity
- stay AndroidManifest.xml Configuration in file
<intent-filter>
<category></category>
<action></action>
</intnet-filter>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
When opening the picture Use different app drawing perhaps Click on
By implicitly Intnet complete
边栏推荐
猜你喜欢
随机推荐
ICML 2022 | 图表示学习的结构感知Transformer模型
CentOS7下安装mysql5.7
SDUT Round 9 2020 Spring Festival campaign
Install MySQL under centos7, and the online articles are not accurate
SQL Server 2016学习记录 --- 连接查询
GKNoise
Xu Ziyang, President of ZTE: 5nm chip will be launched in 2021
Shortest path topic
GKRandom
GKCheckerboardNoiseSource
a different object with the same identifier value was already associated with the session
第一篇:UniAPP的小程序跨端开发-----创建uniapp项目
粒子群解决tsp的技术问题
Multithreading and high concurrency (III) -- source code analysis AQS principle
5、Window端实现Mapreduce程序完成wordcount功能
ZTE: 5nm 5g base station chip is being introduced!
Batch Normlization
ACM winter vacation training 6
8、Yarn系统架构与原理详解
Problem summary file









