intent 和intent Filters

startActivity()的机制

用到了IBinder ipc 用到了进程间通讯机制

activity有四种LaunchMode

当startActivity()的时候不知道启动的是不是和自己的activity在一个

进程中。所以要用 IPC 进程间通讯来调用

简单的使用方法

1

A.class中

1
2
3
Intent
intent = 
new Intent(A.this,
B.
class);
intent.putExtra("sundy.demo""你好");
startActivity(intent);

B.class中

1
2
3
Intent
intent = 
this.getIntent();
String value
= intent.getExtras().getString(
"key");
Toast.makeText(this,
value, 
1).show();

2

A.class中

1
2
3
4
Intent
intent = 
new Intent();
intent.putExtra("key""123");
intent.setAction("com.wang.cn");
startActivity(intent);

B。

class中

.

1
2
3
Intent
intent = 
this.getIntent();
String value
= intent.getExtras().getString(
"key");
Toast.makeText(this,
value, 
1).show();

要在mainfest中设置B。clas的activity中的intent-filter的action中设置

1
2
3
4
5
6
7
<activity
android:name=
".B" >
            <intent-filter>
                <action
android:name=
"com.wang.cn" />
 
                <category
android:name=
"android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

必须写上 <category android:name="android.intent.category.DEFAULT" />这一句不然会报错。。

3. 简单的打电话 代码

1
2
3
4
5
Intent
intent = 
new Intent();
 
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:12345645555"));
startActivity(intent);

setAction和setData都是系統定義好 。這裡仅仅說下使用方法

4.获取data中的值

A。class中

1
2
3
4
Intent
intent = 
new Intent();
intent.setAction("com.wang.cn");
intent.setData(Uri.parse("tel:12345645555"));
startActivity(intent);

B。class中

1
2
3
4
Intent
intent = 
this.getIntent();
 
String uri
= intent.getDataString();
Toast.makeText(this,
uri, 
1).show();

setAction和setData都是系統定義好 。這裡仅仅說下使用方法

1
2
3
4
5
6
7
8
9
10
<activity
android:name=
".Rose" >
            <intent-filter>
                <action
android:name=
"com.wang.cn" />
 
                <category
android:name=
"android.intent.cat 
egory.DEFAULT"
 />
 
                <data
android:scheme=
"tel" >
                </data>
            </intent-filter>
        </activity>

5.startActivityForResult 方法

A。

class中

1
2
3
Intent
intent = 
new Intent();
intent.setClass(A.this,B.class);
startActivityForResult(intent, 123);

在A。

clas的activity中 导入系统的onActivityResult方法

1
2
3
4
5
6
7
8
9
@Override
    protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
        //
TODO Auto-generated method stub
        super.onActivityResult(requestCode,
resultCode, data);
        if (resultCode
== 
321)
{
            String value
= data.getExtras().getString(
"name");
            Toast.makeText(this,
value, 
1).show();
        }
    }

B.class中

1
2
3
4
5
6
7
8
9
10
11
button.setOnClickListener(new OnClickListener()
{
 
            @Override
            public void onClick(View
arg0) {
 
                Intent
intent =
this.getIntent();
                intent.putExtra("name""111111111");
                setResult(321,
intent);
                finish();
            }
        });

当resultCode一样的时候 回传值成功。。

6.intent 传递 对象 类  等等


intent和intentfilter的更多相关文章

  1. Intent和IntentFilter详解

    Intent用于启动Activity,Service, 以及BroadcastReceiver三种组件, 同时还是组件之间通信的重要媒介. 使用Intent启动组件的优势1, Intent为组件的启动 ...

  2. [转]android笔记--Intent和IntentFilter详解

    Intent用于启动Activity, Service, 以及BroadcastReceiver三种组件, 同时还是组件之间通信的重要媒介. 使用Intent启动组件的优势1, Intent为组件的启 ...

  3. android学习日记20--连接组件之Intent和IntentFilter

    上次刚了解完Android的四大组件,现在学习组件间通信的Intent和IntentFilter 一.Intent 1.简述 Intent(意图)在应用程序运行时连接两个不同组件,是一种运行时的绑定机 ...

  4. Intent及IntentFilter具体解释

    Intent用于启动Activity, Service, 以及BroadcastReceiver三种组件, 同一时候还是组件之间通信的重要媒介. 使用Intent启动组件的优势 1, Intent为组 ...

  5. Android应用程序组件之间的通信Intent和IntentFilter

    Android应用程序的基本组件,这些基本组建除了Content Provider之外,几乎全部都是依靠Intent对象来激活和通信的. 下面介绍Intent类,并通过例子来说明Intent一般用法 ...

  6. Android的Intent和IntentFilter应用说明一例

    很多人对文档中的Intent和IntentFilter不理解是什么意思,我这里举例解释下. Intent字面意思就是目标,目的.通俗一点,需要达成某些目标,则需要提供一些动作,这些目标的分类,以及达成 ...

  7. Intent和IntentFilter简介

    Intent和IntentFilter简介 Intent和IntentFilter简介 意图Intent分类: 显式意图:利用class找到对方,在同一个应用程序类可以方便使用,但是在不同的应用程序无 ...

  8. android笔记--Intent和IntentFilter详解

    本文转载自:https://www.cnblogs.com/liushengjie/archive/2012/08/30/2663066.html 本文转载自:https://www.cnblogs. ...

  9. Android开发之隐式Intent中Intent-filter的三个属性-action,category,data

    使用隐式Intent时,需要使用到意图过滤器Intent-filter.Intent-filter含有三个属性:action,category,data.通过这三个属性的组合,可以启动想要启动的act ...

随机推荐

  1. 自定义复选框 checkbox 样式

    默认的复选框样式一般在项目中都很少用 ,看起来也丑丑的.这里提供一个优化样式后的复选框.原理就是隐藏掉默认样式,在用设计好的样式替代 html结构 <div> <input type ...

  2. php之分页类代码

    /* 思路 1.把地址栏的URL获取 2.分析URL中的query部分--就是?后面传参数的部分 3.query部分分析成数组 4.把数组中的page单元,+1,-1,形成2个新的数组 5.再把新数组 ...

  3. js时间戳转为日期格式

    转自:http://wyoojune.blog.163.com/blog/static/57093325201131193650725/ 这个在php+mssql(日期类型为datetime)+aja ...

  4. TatukGIS - GisDefs - CreateMSJET 函数

    函数名称  CreateMSJET 所在单元  GisDefs 函数原型           function CreateMSJET(const _path: String): String;   ...

  5. 基于cx_freeze编译PyQt4程序(numpy & scipy)

    当开发完成PyQt4程序后,需要提供给他人使用,这时最好的办法是将Python程序编译成exe文件. 通常我采用cx_freeze完成这个工作,即编写setup.py文件,执行python setup ...

  6. 那些年被我坑过的Python——不得不知(第二章)

    问题一: Python3.5.X中的数据类型有哪些? 答:包括整型.布尔型.字符串型.浮点型.复数.列表.字典.集合.元组. 细化来说: 1.整型包括短整型和长整型,不过我们不必过度操心细节,因为短整 ...

  7. iOS开发工程师笔试题

    iOS开发工程师笔试题 1.   Object-c的类可以多重继承么?可以实现多个接口么?Category是什么?重写一个类的方式用继承好还是分类好?为什么? Object-c的类不可以多重继承:可以 ...

  8. Raspberry PI(树莓派)安装ZMAP

    以前配置树莓派安装ZMAP一直没有装成功,今天又试了下,装成功了,记录下. Good Job. Zmap地址: https://zmap.io/documentation.html step1: gi ...

  9. 常见的HTTPS攻击方法

    0x00 背景 研究常见的https攻击方法 Beast crime breach,并针对https的特性提出一些安全部署https的建议. 针对于HTTPS的攻击,多存在于中间人攻击的环境中,主要是 ...

  10. PhpStorm常用快捷键大全

    常用快捷键(keymaps:Default情况下)注意:部分快捷键,必须在没有更改快捷键的情况下才可以使用 功能键Esc键 返回编辑器窗口F1 打开在线帮助F2 (Shift+F2) 下/上高亮错误或 ...