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. 《tr命令》-linux命令五分钟系列之六

    本原创文章属于<Linux大棚>博客. 博客地址为http://roclinux.cn. 文章作者为roc 希望您能通过捐款的方式支持Linux大棚博客的运行和发展.请见“关于捐款” == ...

  2. 如何将eclipse里的项目发布到github

    首先,给eclipse安装上EGit 在“Help > Install new software”中添加 http://download.eclipse.org/egit/updates 两个都 ...

  3. dedecms织梦导航栏二级菜单的实现方法

    dede导航下拉菜单,一级栏目增加二级下拉菜单   使用dedecms5.6——5.7 将这段代码贴到templets\default\head.htm文件里<!-- //二级子类下拉菜单,考虑 ...

  4. 【技术宅3】截取文件和url扩展名的N种方法

    //截取文件扩展名的N种方法   //第1种 //strrchr() 函数查找字符在指定字符串中最后一次出现的位置,如果成功,则返回其后面的字符串 //返回带有点的扩展名 function get_e ...

  5. DOS命令行使用pscp实现远程文件和文件夹传输(转)

    转自 http://snailwarrior.blog.51cto.com/680306/141201   pscp是putty安装包所带的远程文件传输工具,使用和Linux下scp命令相似,具体的使 ...

  6. 在 iOS 应用中直接跳转到 AppStore 的方法--备用

    找到应用程序的描述链接,比如:http://itunes.apple.com/gb/app/yi-dong-cai-bian/id391945719?mt=8 然后将 http:// 替换为 itms ...

  7. .Echo 命令中经常提到回显,是什么意思?

    C:\>echo on C:\>date /t2006-08-06 星期日 C:\>以上内容是在打开回显的情况下执行的,其实我们想看到的只有2006-08-06 星期日这一行内容,但 ...

  8. hibernate 一张数据表的流程

    1. 写一个domain类来映射数据库表 2. 写一个*.hbm.xml文件来配置映射 <?xml version="1.0"?> <!DOCTYPE hiber ...

  9. 定义任务打印gradle下载的jar包位置

    //定义任务打印gradle下载的jar包位置task showMyCache { configurations.compile.each { println it }}

  10. hdu 5139 Formula

    http://acm.hdu.edu.cn/showproblem.php?pid=5139 思路:这道题要先找规律,f(n)=n!*(n-1)!*(n-2)!.....1!;  不能直接打表,而是离 ...