当前位置:网站首页>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
边栏推荐
- ACM寒假集训#6
- 20200229 training match L1 - 2 delete the substring in the string (20 points)
- SQL Server 2016 learning records - data update
- SQL Server 2016 learning record - nested query
- RoboCup (2D) experiment 50 questions and the meaning of main functions
- 287. Find the Duplicate Number
- SQL Server 2016 学习记录 --- 数据定义
- 非关系型数据库MongoDB的特点及安装
- Xu Ziyang, President of ZTE: 5nm chip will be launched in 2021
- SQL Server 2016学习记录 --- 单表查询
猜你喜欢

Sword finger offer

Aqua Data Studio 18.5.0 export insert statement

Install mysql5.7 under centos7

ACM寒假集训#5

C language secondary pointer explanation and example code

Install Office customization. Troubleshooting during installation

Typora tutorial

django-celery-redis异步发邮件

Shortest path topic

ICML 2022 | 图表示学习的结构感知Transformer模型
随机推荐
GKNoiseSource
Batch Normlization
机器学习--手写英文字母3--工程特点
Aqua Data Studio 18.5.0 export insert statement
ogg参数filter的使用问题【急】
GKRidgedNoiseSource
ACM winter vacation training 6
生成对抗网络在DeepFake中的未来
GKCheckerboardNoiseSource
Add new startup logo and startup / shutdown animation in mt6735
string matching
Typora tutorial
SQL Server 2016 学习记录 ---视图
SQL Server 2016 learning records - single table query
在mt6735中添加新的开机logo与开\关机动画
SQL Server 2016 learning records - set query
20200217 training match L1 - 7 2019 is coming (20 points)
RoboCup (2D) experiment 50 questions and the meaning of main functions
SQL Server 2016 学习记录 --- 数据更新
Powerful and unique! Yingzhong technology 2020 10th generation core unique product launch