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. C# 跨线程访问控件

    this.BeginInvoke(new Action(() => { this.StatusProgressBar_ExecutingTaskStatus.Value = (int)value ...

  2. 实例:jQuery实现标签切换

    具体实现效果如图: 原理很简单,就是监听鼠标滑动和点击事件.在第一个标签切换的示例中,当鼠标滑过某个标签时,就把class转移到当前标签.这里用到的jQuery方法主要是each()确定当前是哪一个标 ...

  3. opencv之图像膨胀

    #include <cv.h> #include <highgui.h> void main() { IplImage* src; IplImage*dst; src=cvLo ...

  4. RemoteViews嵌入ListView复杂布局

    from http://blog.csdn.net/liliang497/article/details/8308313 主要函数 public void setRemoteAdapter (int ...

  5. python 编程之计算器

    作业: 使用正则表达式和递归实现计算器功能. 实现: 1.实现带括号的计算 2.实现指数.加减乘除求余等功能 一.实例说明: 本实例自己写了个版本,但依旧存在一点bug,例:-2-2等计算问题,故最后 ...

  6. oe 仓库管理

    需求情景: 销售电商, 其中有些产品 为代理销售(公司不管理库存,建立SO后直接由对应的供应商发货即可) 解决方案: SO 生成 DO 时候 , 源库存的取得逻辑        SO-->SHO ...

  7. MySql拾遗

    1.“1130-Host is not allowed to connect to this MySQL server” 满世界的人都告诉你,到user表中把root + localhost的“loc ...

  8. xamarin SimpleAdapter绑定出错问题

    问题:今天在实验xamarin中SimpleAdapter绑定到ListView时,出现闪退的现象, 见图: 解决方法: SimpleAdapter中的构造函数public SimpleAdapter ...

  9. C#,Java,C++中的finally关键字

    博客原文:http://hankjin.blog.163.com/blog/static/33731937201031511305338/ 先说C++,标准C++不支持finally, 如果要实现fi ...

  10. 教你在Java的普通类中轻松获取Session以及request中保存的值

    曾经有多少人因为不知如何在业务类中获取自己在Action或页面上保存在Session中值,当然也包括我,但是本人已经学到一种办法可以解决这个问题,来分享下,希望对你有多多少少的帮助! 如何在Java的 ...