最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android?Intent通信詳細講解

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

Intent

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

Intent 對象屬性:

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

Component name:

設(shè)置Intnet 組件對象 名稱 通過 包名 + 類名 確定唯一的一個activity

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

setComponent(componentName)

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

Action & Data

接下來動作 和 對應(yīng)數(shù)據(jù)

Action 屬性和Data 屬性

第一步在 manifest 設(shè)置開啟電話和郵件的權(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 共用 點擊打電話 和 發(fā)送郵件按鈕 進行 跳轉(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)聽器對象 方法共用
    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)用撥號面板
                    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 進行分類, 將對應(yīng)Activity 進行分類

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 共用 點擊打電話 和 發(fā)送郵件按鈕 進行 跳轉(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)聽器
        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 屬性

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

Intnet 種類

顯示Intnet:

創(chuàng)建Intnet對象 -> 目標組件 ->啟動 目標組件:

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

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

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

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

Intent Filter

Activity A 通過category + action + data 作為Filter的條件刷選出來的ActivityB 是目標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>

打開圖片時候 采用不同app畫圖 或者 點擊

通過隱式Intnet 完成

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

相關(guān)文章

  • Android軟件自動更新實現(xiàn)代碼

    Android軟件自動更新實現(xiàn)代碼

    這篇文章主要為大家詳細介紹了Android軟件自動更新實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Flutter開發(fā)之Widget自定義總結(jié)

    Flutter開發(fā)之Widget自定義總結(jié)

    這篇文章主要給大家介紹了關(guān)于Flutter開發(fā)中Widget自定義的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用Flutter具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • Android Studio 3.5版本JNI生成SO文件詳解

    Android Studio 3.5版本JNI生成SO文件詳解

    這篇文章主要介紹了Android Studio 3.5版本JNI生成SO文件詳解,想了解JNI的同學(xué),可以參考下
    2021-04-04
  • Android第三方登錄之QQ登錄

    Android第三方登錄之QQ登錄

    這篇文章主要為大家詳細介紹了Android第三方登錄之QQ登錄,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • so加載Linker跟NameSpace機制詳解

    so加載Linker跟NameSpace機制詳解

    這篇文章主要為大家介紹了so加載Linker跟NameSpace機制詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • Android打造屬于自己的新聞平臺(客戶端+服務(wù)器)

    Android打造屬于自己的新聞平臺(客戶端+服務(wù)器)

    這篇文章主要為大家詳細介紹了Android打造屬于自己的新聞平臺的相關(guān)資料,Android實現(xiàn)新聞客戶端服務(wù)器,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • 詳解Android中常見的內(nèi)存優(yōu)化及內(nèi)存泄露場景

    詳解Android中常見的內(nèi)存優(yōu)化及內(nèi)存泄露場景

    本文主要給大家介紹了Android中常見的內(nèi)存優(yōu)化及Android開發(fā)中容易造成內(nèi)存泄露的場景,對我們的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2023-08-08
  • Android實現(xiàn)發(fā)送短信功能實例詳解

    Android實現(xiàn)發(fā)送短信功能實例詳解

    這篇文章主要介紹了Android實現(xiàn)發(fā)送短信功能的方法,結(jié)合實例形式較為詳細的分析了Android實現(xiàn)發(fā)送短信的原理、步驟與相關(guān)實現(xiàn)技巧,需要的朋友可以參考下
    2016-02-02
  • 基于Android SQLite的使用介紹

    基于Android SQLite的使用介紹

    本篇文章小編為大家介紹,基于Android SQLite的使用說明,需要的朋友參考下
    2013-04-04
  • Android使用Shape實現(xiàn)ProgressBar樣式實例

    Android使用Shape實現(xiàn)ProgressBar樣式實例

    本篇文章主要介紹了Android使用Shape實現(xiàn)ProgressBar樣式實例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04

最新評論

理塘县| 博白县| 阿合奇县| 洪江市| 彭水| 孟连| 阿拉善左旗| 建平县| 凤城市| 云和县| 湄潭县| 始兴县| 泉州市| 马鞍山市| 临澧县| 武义县| 微博| 房产| 西乡县| 乐山市| 淮南市| 汽车| 那坡县| 寿阳县| 成都市| 南昌县| 乌兰县| 云梦县| 秦皇岛市| 加查县| 邹平县| 文化| 湄潭县| 门头沟区| 文昌市| 娱乐| 浦江县| 阳东县| 哈巴河县| 政和县| 梧州市|