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. 极简主义,对逻辑操作符||和&&深度运用的理解

    丧心病狂的代码压缩好像违背了愉快阅读的本真,所以刨根问底想要了解个究竟,最后发现这不只是前端大牛装逼卖萌的绝技,也是代码洁癖爱好者的利器,毕竟这样看上去确实蛮优雅的; 一开始,我们接触到的代码是这样的 ...

  2. php设计模式之迭代器模式

    今天的PHP设计模式系列的主角是迭代器(Iterator)模式,迭代器模式提供了抽象:位于对象图不明部分的一组对象(或标量)集合上的迭代. 迭代器(Iterator)模式,它在一个很常见的过程上提供了 ...

  3. 关于android:configChanges的属性

    一般在AndroidManifest.xml文件中都没有使用到android:configChanges="keyboardHidden|orientation"配置,当然还是很有 ...

  4. GPUImage 自定义滤镜

    GPUImage 自定义滤镜 GPUImage 是一个基于 GPU 图像和视频处理的开源 iOS 框架.由于使用 GPU 来处理图像和视频,所以速度非常快,它的作者 BradLarson 称在 iPh ...

  5. 优化MYSQL FILESORT

    用Explain分析SQL语句的时候,经常发现有的语句在Extra列会出现Using filesort,根据mysql官方文档对他的描述: 引用 MySQL must do an extra pass ...

  6. Scut DirCenter 网站编辑、搭建与调试

    直接利用 Scut 提供的服务器管理工具进行服务器管理. 教程:https://github.com/ScutGame/Scut/wiki/DirServer. 几个注意点: 下载的数据库导入bat是 ...

  7. 复杂事件处理——Esper入门(示例程序)

    前面对Esper Quick Start & Tutorial进行了简单描述,希望各位看官能够大致了解what is Esper,甚至对how to work有朦朦胧胧的了解. 开发一个Esp ...

  8. BZOJ 1012 最大数

    Description 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. 2. ...

  9. ReiserFS与EXT3的比较

    ReiserFS与EXT3的比较 最近,我刚从ReiserFS文件系统转到了ext3日志文件系统.我是一个ReiserFS的忠实追随者,并且直到现在我也没有改变我对该文件系统的看法.我之所以转而使用e ...

  10. 学习C++所需看的书和顺序

    初学: <C++ 编程思想> <C++ Primer><The C++ Programming Language> 提高: <C++ 的发展与演化> & ...