zoukankan      html  css  js  c++  java
  • Intent

    Android 4大组件之间需要交互,这个时候就有Intent来交互。

    Intent是具有相关数据负载的操作。

    1.URL

    intent.setData(Uri uri);

    intent.getData(Uri uri);

    图片选择程序, onPageResult返回的intent带回的就是图片ID的uri。

    2.Intent过滤器

    Intent intent = new Intent(Intent.ACTION_VIEW);

    intent.setdata(Uri.prase("http://www.google.com"));

    activity.startActivity(intent);

    一般情况下,会跳出一个列表,然你选择一个app来执行该段程序,问题是

    系统是怎么知道需要哪些程序的呢?

    在定义activity或者其他组件的时候,会定义<intent-filter>, 该字段就是用来筛选activity的。

    host

    mimetype

    path

    port

    pathParent

    pathPerfix

    scheme

       其中URL由四部分组成:它有四个属性scheme、host、port、path对应于URI的每个部分。

           例如:content://com.wjr.example1:121/files

           scheme部分:content

           host部分:com.wjr.example1

           port部分:121

           path部分:files

    intent.settype("video/*"); == mimetype

     <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.BROWSABLE" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:scheme="http" />
      <data android:scheme="https" />
      <data android:mimeType="text/html" />
      <data android:mimeType="text/plain" />
      <data android:mimeType="application/xhtml+xml" />
      <data android:mimeType="application/vnd.wap.xhtml+xml" />
      </intent-filter>

    3.extra

    put:

    Intent.putextra(key,value);

    ...

    get:

    Bundle bundle = intent.getextras();

    4.category

    CATEGORY_LAUNCH  该项目可以再启动项中显示

    CATEGORY_HOME   该项目可以随系统启动而启动,一般launcher就设为这个

    5.ACTION_PICKER

    当我们使用ACTION_PICKER来启动activity时,它会根据intent设置的URI来筛选,

    当在新activity中选择某个item后,会在原来activity中的OnActivityResult中的intent带回URI。

    6.ACTION_GET_CONTENT

     ACTION_GET_CONTENT与ACTION_PICKER类似,只是后者使用URL来过滤,而前者使用mimetype来筛选。

    7.PendingIntent

    作用就是在activity上下文销毁后,也可以使用intent,最常用的地方就是notification。

  • 相关阅读:
    【caffe】epoch,[batch_size],iteration的含义
    OAuth2.0学习(1-6)授权方式3-密码模式(Resource Owner Password Credentials Grant)
    OAuth2.0学习(1-5)授权方式2-简化模式(implicit grant type)
    OAuth2.0学习(1-4)授权方式1-授权码模式(authorization code)
    OAuth2.0学习(1-3)OAuth2.0的参与者和流程
    OAuth2.0学习(1-1)OAuth2.0是什么?
    nodejs(1-1)
    HTTP协议扫盲(一)HTTP协议的基本概念和通讯原理
    MySql入门(2-2)创建数据库
    SpringCloud的注解:EnableEurekaClient vs EnableDiscoveryClient
  • 原文地址:https://www.cnblogs.com/deman/p/3979645.html
Copyright © 2011-2022 走看看