[转]Activity详解 Intent显式跳转和隐式跳转
- Activity 生命周期
显式 Intent 调用1 //创建一个显式的 Intent 对象(方法一:在构造函数中指定)2 Intent intent = new Intent(Intent_Demo1.this, Intent_Demo1_Result1.class);34 Bundle bundle = new Bundle();5 bundle.putString("id", strID);6 intent.putExtras(bundle);78 intent.putExtra("name", "bbb");9 intent.putExtra("userInfo", new UserInfo(1, "name"));10 startActivity(intent);1112 //创建一个显式的 Intent 对象(方法二:用 setClass 方法)13 Intent intent = new Intent();14 Bundle bundle = new Bundle();15 bundle.putString("id", strID);16 intent.setClass(Intent_Demo1.this, Intent_Demo1_Result1.class);17 intent.putExtras(bundle);18 startActivity(intent);1920 //创建一个显式的 Intent 对象(方法三:用 setClass 方法)21 Intent intent = new Intent();22 Bundle bundle = new Bundle();23 bundle.putString("id", strID);24 intent.setClassName(Intent_Demo1.this, "com.great.activity_intent.Intent_Demo1_Result1");25 intent.putExtras(bundle);26 startActivity(intent);2728 //创建一个显式的 Intent 对象(方法四:用 setComponent 方法)29 Intent intent = new Intent();30 Bundle bundle = new Bundle();31 bundle.putString("id", strID);32 //setComponent方法的参数:ComponentName33 intent.setComponent(new ComponentName(Intent_Demo1.this, Intent_Demo1_Result1.class));34 intent.putExtras(bundle);35 startActivity(intent);Intent隐式跳转 Action1 //创建一个隐式的 Intent 对象:Action 动作2 /**3 * 这里指定的是 AndroidManifest.xml 文件中配置的4 * <intent-filter>标签中的<action android:name="com.great.activity_intent.Intent_Demo1_Result3" />5 * 所在的 Activity,注意这里都要设置 <category android:name="android.intent.category.DEFAULT" />6 */7 Intent intent = new Intent();8 //设置 Intent 的动作9 intent.setAction("com.great.activity_intent.Intent_Demo1_Result3");10 Bundle bundle = new Bundle();11 bundle.putString("id", strID);12 intent.putExtras(bundle);13 startActivity(intent);AndroidManifest.xml1 <activity android:name="Intent_Demo1_Result3"2 android:label="Intent_Demo1_Result3">3 <intent-filter>4 <action android:name="com.great.activity_intent.Intent_Demo1_Result3" />5 <category android:name="android.intent.category.DEFAULT" />6 </intent-filter>7 </activity>Category 类别1 //创建一个隐式的 Intent 对象:Category 类别2 Intent intent = new Intent();3 intent.setAction("com.great.activity_intent.Intent_Demo1_Result33");4 /**5 * 不指定 Category 或 只指定 AndroidManifest.xml 文件中 <intent-filter> 标签中配置的任意一个 Category6 * <category android:name="android.intent.category.DEFAULT" /> 除外,就可以访问该 Activity,7 */8 intent.addCategory(Intent.CATEGORY_INFO);9 intent.addCategory(Intent.CATEGORY_DEFAULT);10 Bundle bundle = new Bundle();11 bundle.putString("id", strID);12 intent.putExtras(bundle);13 startActivity(intent);AndroidManifest.xml<activity android:name="Intent_Demo1_Result2"android:label="Intent_Demo1_Result2"><intent-filter><category android:name="android.intent.category.INFO" /><category android:name="android.intent.category.BROWSABLE" /><category android:name="android.intent.category.DEFAULT" /></intent-filter></activity>Date 数据 跳转1 //创建一个隐式的 Intent 对象,方法四:Date 数据2 Intent intent = new Intent();3 Uri uri = Uri.parse("http://www.great.org:8080/folder/subfolder/etc/abc.pdf");45 //注:setData、setDataAndType、setType 这三种方法只能单独使用,不可共用6 //要么单独以 setData 方法设置 URI7 //intent.setData(uri);8 //要么单独以 setDataAndType 方法设置 URI 及 mime type9 intent.setDataAndType(uri, "text/plain");10 //要么单独以 setDataAndType 方法设置 Type11 //intent.setType("text/plain");1213 /**14 * 不指定 Category 或 只指定 AndroidManifest.xml 文件中 <intent-filter> 标签中配置的任意一个 Category15 * <category android:name="android.intent.category.DEFAULT" /> 除外,就可以访问该 Activity16 */17 Bundle bundle = new Bundle();18 bundle.putString("id", strID);19 intent.putExtras(bundle);20 startActivity(intent);AndroidManifest.xml1 <activity android:name="Intent_Demo1_Result2"2 android:label="Intent_Demo1_Result2">3 <intent-filter>4 <category android:name="android.intent.category.DEFAULT" />5 <data6 android:scheme="http"7 android:host="www.great.org"8 android:port="8080"9 android:pathPattern=".*pdf"10 android:mimeType="text/plain"/>11 </intent-filter>12 </activity>13调用系统的的组件//web浏览器Uri uri= Uri.parse("http://www.baidu.com:8080/image/a.jpg");Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent);//地图(要在 Android 手机上才能测试)Uri uri = Uri.parse("geo:38.899533,-77.036476");Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent);//路径规划Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");Intent it = new Intent(Intent.ACTION_VIEW, uri);startActivity(it);//拨打电话-调用拨号程序Uri uri = Uri.parse("tel:15980665805");Intent intent = new Intent(Intent.ACTION_DIAL, uri);startActivity(intent);//拨打电话-直接拨打电话//要使用这个必须在配置文件中加入<uses-permission android:name="android.permission.CALL_PHONE"/>Uri uri = Uri.parse("tel:15980665805");Intent intent = new Intent(Intent.ACTION_CALL, uri);startActivity(intent);//调用发送短信程序(方法一)Uri uri = Uri.parse("smsto:15980665805");Intent intent = new Intent(Intent.ACTION_SENDTO, uri);intent.putExtra("sms_body", "The SMS text");startActivity(intent);//调用发送短信程序(方法二)Intent intent = new Intent(Intent.ACTION_VIEW);intent.putExtra("sms_body", "The SMS text");intent.setType("vnd.android-dir/mms-sms");startActivity(intent);//发送彩信Uri uri = Uri.parse("content://media/external/images/media/23");Intent intent = new Intent(Intent.ACTION_SEND);intent.putExtra("sms_body", "some text");intent.putExtra(Intent.EXTRA_STREAM, uri);intent.setType("image/png");startActivity(intent);//发送Email(方法一)(要在 Android 手机上才能测试)Uri uri = Uri.parse("mailto:zhangsan@gmail.com");Intent intent = new Intent(Intent.ACTION_SENDTO, uri);startActivity(intent);//发送Email(方法二)(要在 Android 手机上才能测试)Intent intent = new Intent(Intent.ACTION_SENDTO);intent.setData(Uri.parse("mailto:zhangsan@gmail.com"));intent.putExtra(Intent.EXTRA_SUBJECT, "这是标题");intent.putExtra(Intent.EXTRA_TEXT, "这是内容");startActivity(intent);//发送Email(方法三)(要在 Android 手机上才能测试)Intent intent = new Intent(Intent.ACTION_SEND);intent.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");intent.putExtra(Intent.EXTRA_SUBJECT, "这是标题");intent.putExtra(Intent.EXTRA_TEXT, "这是内容");intent.setType("text/plain");//选择一个邮件客户端startActivity(Intent.createChooser(intent, "Choose Email Client"));//发送Email(方法四)(要在 Android 手机上才能测试)Intent intent = new Intent(Intent.ACTION_SEND);//收件人String[] tos = {"to1@abc.com", "to2@abc.com"};//抄送人String[] ccs = {"cc1@abc.com", "cc2@abc.com"};//密送人String[] bcc = {"bcc1@abc.com", "bcc2@abc.com"};intent.putExtra(Intent.EXTRA_EMAIL, tos);intent.putExtra(Intent.EXTRA_CC, ccs);intent.putExtra(Intent.EXTRA_BCC, bcc);intent.putExtra(Intent.EXTRA_SUBJECT, "这是标题");intent.putExtra(Intent.EXTRA_TEXT, "这是内容");intent.setType("message/rfc822");startActivity(Intent.createChooser(intent, "Choose Email Client"));//发送Email且发送附件(要在 Android 手机上才能测试)Intent intent = new Intent(Intent.ACTION_SEND);intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");intent.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mp3/醉红颜.mp3");intent.setType("audio/mp3");startActivity(Intent.createChooser(intent, "Choose Email Client"));//播放媒体文件(android 对中文名的文件支持不好)Intent intent = new Intent(Intent.ACTION_VIEW);//Uri uri = Uri.parse("file:///sdcard/zhy.mp3");Uri uri = Uri.parse("file:///sdcard/a.mp3");intent.setDataAndType(uri, "audio/mp3");startActivity(intent);Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent);//音乐选择器//它使用了Intent.ACTION_GET_CONTENT 和 MIME 类型来查找支持 audio/* 的所有 Data Picker,允许用户选择其中之一Intent intent = new Intent(Intent.ACTION_GET_CONTENT);intent.setType("audio/*");//Intent.createChooser:应用选择器,这个方法创建一个 ACTION_CHOOSER IntentstartActivity(Intent.createChooser(intent, "选择音乐"));Intent intent1 = new Intent(Intent.ACTION_GET_CONTENT);intent1.setType("audio/*");Intent intent2 = new Intent(Intent.ACTION_CHOOSER);intent2.putExtra(Intent.EXTRA_INTENT, intent1);intent2.putExtra(Intent.EXTRA_TITLE, "aaaa");startActivity(intent2);// //设置壁纸// Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);// startActivity(Intent.createChooser(intent, "设置壁纸"));//卸载APK//fromParts方法//参数1:URI 的 scheme//参数2:包路径//参数3:Uri uri = Uri.fromParts("package", "com.great.activity_intent", null);Intent intent = new Intent(Intent.ACTION_DELETE, uri);startActivity(intent);//安装APK(???)Uri uri = Uri.fromParts("package", "com.great.activity_intent", null);Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED, uri);startActivity(intent);//调用搜索Intent intent = new Intent();intent.setAction(Intent.ACTION_WEB_SEARCH);intent.putExtra(SearchManager.QUERY, "android");startActivity(intent);
[转]Activity详解 Intent显式跳转和隐式跳转的更多相关文章
- Xamarin android 之Activity详解
序言: 上篇大概的讲解了新建一个android的流程.今天为大家带来的是Activity详解,因为自己在开发过程中就遇到 好几次坑,尴尬. 生命周期 和Java里头一样一样的,如图 图片来源于网上哈, ...
- Android学习笔记4——Activity详解
在 Android 开发过程中,与程序员打交道最多的应该就是作为四大组件之一的 Activity 了.接下来我们就一起来揭开 Activity 的神秘面纱吧~ 一.概述 什么是 Activity(活动 ...
- 详解Android中的四大组件之一:Activity详解
activity的生命周期 activity的四种状态 running:正在运行,处于活动状态,用户可以点击屏幕,是将activity处于栈顶的状态. paused:暂停,处于失去焦点的时候,处于pa ...
- [安卓基础] 009.组件Activity详解
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- C++中构造函数详解及显式调用构造函数
C++构造函数详解及显式调用构造函数 c++类的构造函数详解 一. 构造函 ...
- [Selenium]显式等待 Explicit wait & 隐式等待 Implicit wait
显式等待 Explicit wait 显示等待 , 就是明确的要等到某个元素出现或者某个元素满足某种条件,每隔一段时间检查一次,等不到,就一直等,如果在规定的时间内还没有找到,就跳出来检查间隔的时间和 ...
- Activity的显式跳转和隐式挑战
安卓中Activity的跳转几乎是每一个APP都会用到的技术点.而且他的使用时十分简单的. 这里我们先说一下主要的技术要点: 1.在清单文件中注册新的Activity 2.通过意图跳转 这里我们看一下 ...
- MVC图片上传详解 IIS (安装SSL证书后) 实现 HTTP 自动跳转到 HTTPS C#中Enum用法小结 表达式目录树 “村长”教你测试用例 引用provinces.js的三级联动
MVC图片上传详解 MVC图片上传--控制器方法 新建一个控制器命名为File,定义一个Img方法 [HttpPost]public ActionResult Img(HttpPostedFile ...
- Android笔记(七十四) 详解Intent
我们最常使用Intent来实现Activity之间的转跳,最近做一个app用到从系统搜索图片的功能,使用到了intent的 setType 方法和 setAction 方法,网上搜索一番,发现实现转跳 ...
随机推荐
- arch优化开机
查看开机时间 systemd-analyze 具体开机时间 systemd-analyze blame 你可以systemctl --all | grep not-found 查看有哪些服务挂掉了.然 ...
- xv6/sh.c
// Shell. #include "types.h" #include "user.h" #include "fcntl.h" // P ...
- WebBrowser中运行js
HtmlElement script = wf.WebBrowser.Document.CreateElement("script"); script.SetAttribute(& ...
- 002_让你的linux虚拟终端五彩缤纷(1)——LS颜色设置
- Python连接Access数据库
前言 今天想要用Python访问Access数据库,折腾了半天,特记录一下 背景 最近想将一些文件记录下来,存入数据库,为此拿LabVIEW写了一个版本,记录环境配置为: LabVIWE:2015 A ...
- static变量和final变量
1.static变量 按照是否静态的对类成员变量进行分类可分两种:一种是被static修饰的变量,叫静态变量或类变量:另一种是没有被static修饰的变量,叫实例变量.两者的区别是: 对于静态变量在内 ...
- C语言地址对齐(转)--网络编程之结构体大小的计算
什么是地址对齐? 现代计算机中内存空间都是按照字节(byte)划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定变量的时候经常在特定的内存地址访问,这就需要各类型数 ...
- 欧拉回路&欧拉通路判断
欧拉回路:图G,若存在一条路,经过G中每条边有且仅有一次,称这条路为欧拉路,如果存在一条回路经过G每条边有且仅有一次, 称这条回路为欧拉回路.具有欧拉回路的图成为欧拉图. 判断欧拉通路是否存在的方法 ...
- scrapy抓取小说
用scrapy建立一个project,名字为Spider scrapy startproject Spider 因为之前一直用的是电脑自带的python版本,所以在安装scrapy时,有很多问题,也没 ...
- 洛谷 P1469 找筷子 题解
题目传送门 先排序一遍,再一个一个判断是否有偶数个.注意for循环要i+=2. #include<bits/stdc++.h> using namespace std; ]; int ma ...