zoukankan      html  css  js  c++  java
  • Intent_显式与隐式

    android四核心activity,service,broadcast receiver和content provider。除了content provider之外,彼此的通信都要使用Intent对象来进行。

    Intent对象描述了要执行的结果是什么,基本内容可以氛围:componentName组件名称,action动作名称,data数据,category类别,extra返家数据和flag标志位6个部分。

    所谓的显示intent就是我们常用的Intent.setclass(xxx.this,xxx.class),也就是指定componentName组件名称。

    相对的隐式调用就是没有明确指出目标组件名称的情况。

    隐式Intent则是可以直接通过androidMainfest中的<intent-filter> 启动activity

            <activity android:name=".Intent1_test">
                <intent-filter>
                    <category android:name="android.intent.category.DEFAULT"></category>
    
                    <action android:name="Intent1"></action>
                </intent-filter>
            </activity>


    启动时候,也可以用一个静态常量来表示

    startActivity(new Intent("Intent1"));

    //或者
    startActivity(new Intent(Intent1_test.ACTION));//Intent1_test为activity的名,ACTION为常量:public static final String ACTION = "Intent1";

    隐式Intent更重要的还是可以启动别的APP的活动页面,只需要将Intent1改为对应的名称即可

    startActivity(new Intent("Intent1"));


    关于名字的命名法也是有  包名 +intent.action + activity名

    如果你要明确拒绝被别的app启动某一个活动,需要在mainFest的活动标签中写明exported="false"

            <activity android:name=".Intent1_test" android:exported="false">
                <intent-filter>
                    <category android:name="android.intent.category.DEFAULT"></category>
    
                    <action android:name="Intent1"></action>
                </intent-filter>
  • 相关阅读:
    struts2笔记之if控制标签
    struts2标签之iterator遍历集合
    struts2获得session和request
    数据库操作语句
    weixinapp api
    struts2笔记之tree标签输出树
    struts2笔记之整合Tiles
    C++中的符号
    JSP布局相关使用
    5.Github仓库
  • 原文地址:https://www.cnblogs.com/lyxin/p/5778370.html
Copyright © 2011-2022 走看看