Android 通訊的橋樑 Intent

來源:互聯網
上載者:User

雖然比較簡單,但還是把主要內容提一下。 

 

Intent的使用

Intent 可以啟動一個Activity,也可以啟動一個service,還可以發起一個廣播  

Activity                       startActivity(),startActivityForResult();

Service                        startService(),bindService()

BroadCast                 sendBroadcast(),sendOrderedBroadcast(),sendStickyBroadcast();

 

Intent的Action屬性

隱式指定:

比如在AActivity中聲明,

My_Action = “com.king.android.my_action”;

Intent intent = new Intent();

Intent.setAction(My_Action);

 

注意了

BActiivty接受:

Intent intent = getAction();

String action =- intent.getAction();

 

AndroidMainFest.xml檔案

<activity android:name=".BActivity"

                  android:label="@string/app_name">

            <intent-filter>

                <action android:name=" com.king.android.my_action " />  指定過慮條件。

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

 

訪問系統的Action屬性,

Intent的Data屬性

Intent的Category屬性:

如CATEGORY_LAUNCHER,則應用程式出現在最上面, CATEGORY_HOME則回到home介面。

Intent的Extras屬性雖然簡單,卻是重點,

 

系統標準的Activity Action應用 比較多,要用的時候,自己在網上查查吧。

 

Intent的策略需要注意一下

1. Action

2. Category

3. Data

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.