Android——Intent(意图)

//Intent的属性
Intent in1 = new Intent(); ComponentName componentName = new ComponentName(this,Activity2.class); in1.setComponent(componentName);//设置显示意图 in1.setAction(Intent.ACTION_DIAL);//用特别的字符串规定一些功能的Activity 实现隐式意图 唯一性 in1.addFlags(1);//自己规定标记 多个 in1.addCategory("");//多个 //in1.setDataAndTypeAndNormalize();Type Intent intent = new Intent(this,Activity2.class);
main_layout.xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="隐式意图调用"
android:textSize="30dp"
android:onClick="onclick5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="隐式意图调用打电话"
android:textSize="30dp"
android:onClick="onclick6" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="隐式意图直接拨打电话"
android:textSize="30dp"
android:onClick="onclick7" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="回到桌面"
android:textSize="30dp"
android:onClick="onclick8" />
MainActivity.java
//隐式意图的监听
public void onclick5(View view)
{
//只有action的隐式意图
Intent intent = new Intent("hello"); startActivity(intent);
}
public void onclick6(View view)
{
//action的隐式意图
//传数据 data Uri
Uri uri = Uri.parse("tel:110"); Intent intent = new Intent(Intent.ACTION_DIAL,uri); startActivity(intent);
}
public void onclick7(View view)
{
//action的隐式意图
//传数据 data Uri
Uri uri = Uri.parse("tel:110"); Intent intent = new Intent(Intent.ACTION_CALL,uri); startActivity(intent);
}
public void onclick8(View view)
{
//action的隐式意图 //回到桌面
Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); startActivity(intent);
}
AndroidManifext.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chenshuai.test321"> <uses-permission android:name="android.permission.CALL_PHONE" /> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="测试"
android:supportsRtl="true"
android:theme="@style/AppTheme"> <activity android:name=".MainActivity"
android:launchMode="standard">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity2">
<intent-filter>
<action android:name="hello" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Activity3">
<intent-filter>
<action android:name="hello" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application> </manifest>
效果





Android——Intent(意图)的更多相关文章
- Android 之 Intent(意图)
Intent是 Android中重要的桥梁之一,它分为显式意图和隐式意图.接下来分别针对这两种意图进行讲解. 显式意图:通过指定一组数据或动作,激活应用内部的 activity:(相比隐式意图,此做法 ...
- android intent 隐式意图和显示意图(activity跳转)
android中的意图有显示意图和隐式意图两种, 显示意图要求必须知道被激活组件的包和class 隐式意图只需要知道跳转activity的动作和数据,就可以激活对应的组件 A 主activity B ...
- Android组件--意图(Intent)
1. 隐示调用和显示调用 参考资料:http://blog.csdn.net/harvic880925/article/details/38399723 1.概念 1). 显式意图: 能从intent ...
- android:Intent匹配action,category和data原则
1.当你在androidmanifest里面定义了一个或多个action时 你使用隐式意图其他activity或者service时,规定你隐式里面的action必须匹配XML中定义的action,可以 ...
- Android Intent
Intent在Android中的重要性不言而喻.本文主要总结下Intent使用过程中需要注意的一些问题. 1.隐式Intent AndroidManifest.xml声明时<intent-fil ...
- Android总结篇系列:Android Intent
Intent在Android中的重要性不言而喻.本文主要总结下Intent使用过程中需要注意的一些问题. 1.隐式Intent AndroidManifest.xml声明时<intent-fil ...
- Android Intent (可通过URL启动 Activity)
Intent分为两大类: (1)显性的(Explicit) (2)隐性的(Implicit) 对于隐性意图,在某些时候, 应用程序只是想启动具有某种特征的组件, 并不想和某个特定的组件耦合. 使用In ...
- [Android] Intent详解
[转]http://www.cnblogs.com/engine1984/p/4146621.html [正文] Intent组件虽然不是四大组件,但却是连接四大组件的桥梁,学习好这个知识,也非常的重 ...
- Intent(意图)
Intent的中文意思是“意图,目的”的意思,可以理解为不同组件之间通信的“媒介”或者“信使”. 目标组件一般要通过Intent来声明自己的条件,一般通过组件中的<intent-filter&g ...
随机推荐
- jquery ajax方式直接提交整个表单
$.ajax({ type: "POST", url: url, data: $('#form1').serialize(), success: function(msg){ al ...
- Python socket – network programming tutorial
原文:https://www.binarytides.com/python-socket-programming-tutorial/ --------------------------------- ...
- [Grunt] grunt.template
/** * Created by Answer1215 on 11/15/2014. */ module.exports = function(grunt){ grunt.initConfig({ f ...
- (C++)浅谈using namespace std
1.<iostream>和<iostream.h> 在你的编译器include文件夹里面可以看到,二者是两个文件,里面的代码是不一样的. 后缀为.h的头文件c++标准已经明确提 ...
- 出现RST的几种情况
1.端口未打开,C向S发送SYN,去连接S的端口9820,但是S没有打开9820端口,这个时候S发送RST 2.请求超时,C向S发送SYN,S回复ACK+SYN,如果C从发送SYN到收到S的ACK+S ...
- C#获取外网IP地址;C#获取所在IP城市地址
public static string GetIP() { using (var webClient = new WebClient()) ...
- codeforces 558D Guess Your Way Out! II 规律
题目链接 题意: 给出n和q 表示有一棵深度为n的全然二叉树.叶子节点中有恰好一个点是出口 主角从根往下走.但不知道出口在哪里,但主角会获得q个提示. 像这样标号 q个提示 格式: deep [l, ...
- Python中的迭代器漫谈
转自:http://www.jb51.net/article/60706.htm 熟悉Python的都知道,它没有类似其它语言中的for循环, 只能通过for in的方式进行循环遍历.最典型的应用就是 ...
- 如何自动生成Makefile
作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile,如果要想写出一个符合自由软件惯例的M ...
- 使用maven拆分项目
在开发环境中,有时需要专人负责专门的模块,其他模块不需接触,这就需要将项目拆分,如下 fund_demo项目具有三个模块,现将主业务core模块单独提出另建一个项目fund_core,拆分时需要注意相 ...