欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android?Intent通信詳細(xì)講解

 更新時(shí)間:2022年12月17日 15:08:17   作者:上后左愛(ài)  
Android進(jìn)程間通信(IPC,Inter-Process?Communication)底層采用的是?Binder?機(jī)制,具體到應(yīng)用層有網(wǎng)友根據(jù)安卓四大組件將進(jìn)程間通信方式分為對(duì)應(yīng)的四種方式?Activity,?Broadcast,?ContentProvider,?Service

Intent

將Activity 、Serivce 、 BroadReceive 之間通信 使用Intent

Intent 對(duì)象屬性:

  • 1.Action
  • 2. Data
  • 3.Category
  • 4. Extras
  • 5.Flags
  • 6.Component name

Component name:

設(shè)置Intnet 組件對(duì)象 名稱(chēng) 通過(guò) 包名 + 類(lèi)名 確定唯一的一個(gè)activity

類(lèi)似Spring 中Component 根據(jù)component name 設(shè)置或者啟動(dòng)特定的組件

setComponent(componentName)

Intnet intnet = new Intnet();
ComponentName componentName = new ComponentName("com.example","com.example.DetailActivity");
intnet.setComponent(componentName);
startActivity(intnet)

Action & Data

接下來(lái)動(dòng)作 和 對(duì)應(yīng)數(shù)據(jù)

Action 屬性和Data 屬性

第一步在 manifest 設(shè)置開(kāi)啟電話和郵件的權(quán)限

<?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>
        <!--  自定義Activity 需要在mainifests 配置聲明       -->
    </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;
/**
 *  功能: Action Data 共用 點(diǎn)擊打電話 和 發(fā)送郵件按鈕 進(jìn)行 跳轉(zhuǎn)系統(tǒng) 打電話 和郵件界面
 *
 *
 * */
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);
    }
    // 定義監(jiān)聽(tīng)器對(duì)象 方法共用
    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:
                 // 調(diào)用撥號(hào)面板
                    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"));
                    // 設(shè)置短信內(nèi)容
                    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="技術(shù)支持:吉林省明日科技有限公司"
        android:layout_marginTop="20dp"/>
<TextView
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="網(wǎng)址: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="企業(yè)郵箱:mingrisoft@mingrisoft.com"
        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="技術(shù)服務(wù)熱線: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屬性 將Activity 進(jìn)行分類(lèi), 將對(duì)應(yīng)Activity 進(jìn)行分類(lèi)

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;
/**
 *  功能: Action Data 共用 點(diǎn)擊打電話 和 發(fā)送郵件按鈕 進(jìn)行 跳轉(zhuǎn)系統(tǒng) 打電話 和郵件界面
 *
 *
 * */
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //設(shè)置全屏顯示
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        ImageButton imageButton= (ImageButton) findViewById(R.id.imageButton1); //獲取ImageView組件
        //為ImageView組件設(shè)置單擊事件監(jiān)聽(tīng)器
        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 屬性

作用: 讓當(dāng)前的activity 不在歷史棧當(dāng)中保留,當(dāng)用戶離開(kāi)app 再一次進(jìn)入時(shí)候 不在是當(dāng)前Activity 界面 轉(zhuǎn)到系統(tǒng)的主界面

Intnet 種類(lèi)

顯示Intnet:

創(chuàng)建Intnet對(duì)象 -> 目標(biāo)組件 ->啟動(dòng) 目標(biāo)組件:

Intnet intnet = new Intnet(MainActivity.this, 調(diào)用Activity對(duì)象)

隱式Intnet創(chuàng)建對(duì)象不指定 目標(biāo)組件,通過(guò)action , category , data 讓Android 系統(tǒng)自動(dòng)匹配目標(biāo)組件

區(qū)別: 顯示 直接指定目標(biāo)組件名稱(chēng),多常用在應(yīng)用程序內(nèi)部傳遞信息

隱式Intnet:不會(huì)用組件名稱(chēng)定義激活的目標(biāo)組件,多常用在不同應(yīng)用程序之間傳遞信息

Intent Filter

Activity A 通過(guò)category + action + data 作為Filter的條件刷選出來(lái)的ActivityB 是目標(biāo)Activity

在AndroidManifest.xml 文件中配置

 <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>

打開(kāi)圖片時(shí)候 采用不同app畫(huà)圖 或者 點(diǎn)擊

通過(guò)隱式Intnet 完成

到此這篇關(guān)于Android Intent通信詳細(xì)講解的文章就介紹到這了,更多相關(guān)Android Intent通信內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Flutter應(yīng)用程序?qū)崿F(xiàn)隱私屏幕示例解析

    Flutter應(yīng)用程序?qū)崿F(xiàn)隱私屏幕示例解析

    這篇文章主要為大家介紹了Flutter應(yīng)用程序?qū)崿F(xiàn)隱私屏幕示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • Android中RecyclerView實(shí)現(xiàn)分頁(yè)滾動(dòng)的方法詳解

    Android中RecyclerView實(shí)現(xiàn)分頁(yè)滾動(dòng)的方法詳解

    RecyclerView實(shí)現(xiàn)滾動(dòng)相信對(duì)大家來(lái)說(shuō)都不陌生,但是本文主要給大家介紹了利用Android中RecyclerView實(shí)現(xiàn)分頁(yè)滾動(dòng)的思路和方法,可以實(shí)現(xiàn)翻頁(yè)功能,一次翻一頁(yè),也可以實(shí)現(xiàn)翻至某一頁(yè)功能。文中給出了詳細(xì)的示例代碼,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-04-04
  • Android實(shí)現(xiàn)信息彈出框

    Android實(shí)現(xiàn)信息彈出框

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)信息彈出框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • WebView設(shè)置WebViewClient的方法

    WebView設(shè)置WebViewClient的方法

    這篇文章主要介紹了 WebView設(shè)置WebViewClient的方法的相關(guān)資料,希望通過(guò)本文能幫助到大家,需要的朋友可以參考下
    2017-09-09
  • AndroidStudio 配置 AspectJ 環(huán)境實(shí)現(xiàn)AOP的方法

    AndroidStudio 配置 AspectJ 環(huán)境實(shí)現(xiàn)AOP的方法

    本篇文章主要介紹了AndroidStudio 配置 AspectJ 環(huán)境實(shí)現(xiàn)AOP的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • Kotlin對(duì)象的懶加載方式by?lazy?與?lateinit?異同詳解

    Kotlin對(duì)象的懶加載方式by?lazy?與?lateinit?異同詳解

    這篇文章主要為大家介紹了Kotlin對(duì)象的懶加載方式by?lazy?與?lateinit?異同詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • Android App如何防止抓包

    Android App如何防止抓包

    我們要知道常用的抓包方式有Charles和Fiddler,他們通過(guò)在手機(jī)網(wǎng)絡(luò)中添加代理的方式,拿到App的請(qǐng)求,這篇文章主要給大家介紹了關(guān)于Android中App如何防止抓包的相關(guān)資料,需要的朋友可以參考下
    2022-03-03
  • Android仿QQ微信未讀消息小紅點(diǎn)BadgeHelper

    Android仿QQ微信未讀消息小紅點(diǎn)BadgeHelper

    這篇文章主要介紹了Android仿QQ微信未讀消息小紅點(diǎn)的實(shí)現(xiàn),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-09-09
  • Android?SharedPreferences性能瓶頸解析

    Android?SharedPreferences性能瓶頸解析

    這篇文章主要為大家介紹了Android?SharedPreferences性能瓶頸解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02
  • 關(guān)于Kotlin寫(xiě)界面時(shí)諸多控件的點(diǎn)擊事件

    關(guān)于Kotlin寫(xiě)界面時(shí)諸多控件的點(diǎn)擊事件

    這篇文章主要介紹了關(guān)于Kotlin寫(xiě)界面時(shí)諸多控件的點(diǎn)擊事件,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03

最新評(píng)論