Activity详解 Intent显式跳转和隐式跳转

Activity 生命周期

 

 

显式 Intent 调用

 

 1     //创建一个显式的 Intent 对象(方法一:在构造函数中指定)
 2      Intent intent = new Intent(Intent_Demo1.this, Intent_Demo1_Result1.class);
 3      
 4      Bundle bundle = new Bundle();
 5      bundle.putString("id", strID);
 6      intent.putExtras(bundle);
 7      
 8      intent.putExtra("name", "bbb");
 9      intent.putExtra("userInfo", new UserInfo(1, "name"));
10      startActivity(intent);
11      
12      //创建一个显式的 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);
19      
20      //创建一个显式的 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);
27      
28      //创建一个显式的 Intent 对象(方法四:用 setComponent 方法)
29      Intent intent = new Intent();
30      Bundle bundle = new Bundle();
31      bundle.putString("id", strID);
32      //setComponent方法的参数:ComponentName
33      intent.setComponent(new ComponentName(Intent_Demo1.this, Intent_Demo1_Result1.class));
34      intent.putExtras(bundle);
35      startActivity(intent);

 

Intent隐式跳转 Action

 1     //创建一个隐式的 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.xml

1    <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> 标签中配置的任意一个 Category
 6  * <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");
 4 
 5 //注:setData、setDataAndType、setType 这三种方法只能单独使用,不可共用                
 6 //要么单独以 setData 方法设置 URI
 7 //intent.setData(uri);
 8 //要么单独以 setDataAndType 方法设置 URI 及 mime type
 9 intent.setDataAndType(uri, "text/plain");
10 //要么单独以 setDataAndType 方法设置 Type
11 //intent.setType("text/plain");
12 
13 /**
14  * 不指定 Category 或 只指定 AndroidManifest.xml 文件中 <intent-filter> 标签中配置的任意一个 Category
15  * <category android:name="android.intent.category.DEFAULT" /> 除外,就可以访问该 Activity
16  */
17 Bundle bundle = new Bundle();
18 bundle.putString("id", strID);
19 intent.putExtras(bundle);
20 startActivity(intent);

AndroidManifest.xml

 1         <activity android:name="Intent_Demo1_Result2"
 2                   android:label="Intent_Demo1_Result2">
 3             <intent-filter>
 4                 <category android:name="android.intent.category.DEFAULT" />
 5                 <data 
 6                     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 Intent
    startActivity(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);

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/totome/archive/2012/08/30/2664582.html

【Android-Activity】activity的跳转方式(显式跳转&隐式跳转) Activity的显式跳转 显式跳转1: Intent intent=new Intent(this,DemoActivity.class); startActivity(intent); 显式跳转2: Activity的隐式跳转 阅读详情

相关推荐

Vue 10分钟入门VR全景显示 基于photo-sphere-viewer

文章目录前言一、引入photo-sphere-viewer?二、使用步骤1.引入库2.声明容器3.内容加载4.全部代码总结 前言 由于工作的需求,要实现全景图片的展示与预览,本来以为会是一个很难的内容,没想到使用现成的组件photo-sphere-viewer就可以轻松实现,上手只需要10分钟! 一、引入photo-sphere-viewer? 可以直接通过npm进行引入 npm install photo-sphere-viewer 二、使用步骤 1.引入库 photo-sphere-viewer

YIGE_MO的博客 5874

Intent隐式跳转

Intent隐式跳转 中重要方法:setAction()、setData()、setType()、putExtra() Intent大致分为两种:显式Intent和隐式Intent。 一、显示Intent为从一个activity跳转到另一个activity。如:   Intent intent = new Intent(MainActivity.this,SecondAc

gxflh的博客 1321

C#创建COM组件,QT调用COM组件简单测试(VS2008+QT4.6.4)

一. C#创建组件: 1. VS2008新建一个项目,选择Visual C#, Class library 修改Properties下面的AssemblyInfo.cs文件,ComVisible属性设置为True,即:[assembly: ComVisible(true)] 2. 右击项目,选择“属性”, 选择“生成”选项卡,把“为COM互操作注册”勾选上 选择“签名”选项卡,把“

3521

使用Intent进行页面之间的跳转【Intent_1】

本文介绍了使用Intent进行页面之间的跳转,是Intent相关的第一篇文章,还有很多问题没有深入研究,有待解决。后续会慢慢更新相关内容及其他的文章。

xiaoxin想升职加薪 4122

音视频入门:H264、H265概念总结

添加链接描述 什么是H.264与H.265 H.264与H.265都是视频压缩格式,由于视频本身的码流太大,所以需要经过压缩然后再通过网络进行传输。H.264是目前比较主流的压缩算法,像视频会议设备一般都采用这个编码格式。基础的H.264可以支持在1M带宽下传输720P30帧/秒的图像;H.264 HIGH PROFILE支持在512K带宽下传输720P30帧/秒的图像。 H.265是比较新的压缩算法,可以更一步提高压缩比,随着我们现在生活中出现的视频格式越来越大(比如现在基本都是1080P甚至4K的显示器

weixin_40673765的博客 8946

更多 LSTM 变种——应用于 CMAPSS 数据集

本文并模型介绍,只是把一些比较火的技术,像双向注意力机制,自注意力机制这样的比较火的内容,简单的和LSTM堆叠,结果发现效果都不如最基础的,这里作者将本人代码及实现结果,进行展示,给各位想更改LSTM的朋友一些。

2301_77491330的博客 1782

Android Intent显式与隐式跳转详细讲解

Android Intent是一种重要的消息传递机制,可用于在应用程序之间进行通信。Intent 可以分为显式 Intent 和隐式 Intent。显式 Intent 明确指定要启动的 Activity,而隐式 Intent 只指定 Action、Category、Data 等元素,由系统匹配合适的 Activity。Intent 可以传递数据,使用 putExtra() 方法添加键值对即可。数据类型可以是基本类型、字符串、Parcelable 对象等。Intent 还可以启动服务和发送广播。

qq_64125090的博客 3915

15、基于最优传输的协作多视图聚类框架

本文提出了一种基于最优传输理论的协作多视图聚类框架,通过引入协作学习机制在不同视图间建立先验交互,以提升共识聚类的质量。框架包含两种新方法:协作共识投影方法(CoCP)和基于新表示的协作共识方法(CoCNR)。CoCP在全局空间中整合多视图信息并进行共识投影,而CoCNR则通过协作编码生成新的数据表示以实现更优聚类。方法利用熵正则化的Wasserstein距离与Wasserstein重心,有效捕捉数据分布间的几何结构,并通过聚合步骤获得统一模型。实验结果表明,所提方法在多个数据集上均优于现有方法,具有良好的

gpt4scribbler的博客 89

Android-activity-隐式Intent实现活动跳转(三种方法)

Android-activity-隐式Intent实现活动跳转

深度安全实验室 2229

17|CI/CD 集成与质量门禁:让精准测试进入发布流水线

本文讲解精准测试如何接入 CI/CD 流水线,并通过质量门禁辅助发布决策。测试开发工程师。Java 后端开发工程师。质量平台 / DevOps 平台建设者。想了解精准测试落地方法的技术负责人。

专注 AI 精准测试平台实战落地,分享从代码 Diff 到回归决策的完整工程闭环。主张“先建数据链路,再上 AI 智能”,让测试从“靠经验”走向“基于风险”。 74

芯片原厂linux驱动开发的分享

大家好,我是XX,来自湖南XX学院,电子信息18级,也曾在创新基地控制组学习过两三年,毕业后就职于一家芯片原厂的解决方案部,担任驱动工程师的职位,算上实习期,我的工作时长已有两年。在此我想将这两年期间学习与积累到的一些经验输出出来,与大家一同分享。知识面有限,只能简单介绍一些驱动开发方向的一些经验,且由于经验尚浅,文中难免会有一些疏漏和错误之处,还请大家积极地批评指正。

嵌入式技术开发 859

Intent隐式跳转应用(开发设置权限管理界面)

1.Intent跳转应用有显式和隐式区分 显式跳转就是 Intent intent = new Intent(classA.this, classB.class); startActivity(intent); 隐式跳转有三种 (1.)Intent mSettingsIntent = new Intent(Intent.ACTION_MAIN) .setAction(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); startActivity(mSettingsInt

qq_36390114的博客 2079

福建公共资源交易平台 portal-sign与响应Data解密逆向实录

本文分析了福建公共资源交易电子公共服务平台的接口加密机制。通过抓包和代码分析,发现请求头中的portal-sign由MD5算法生成,包含固定秘钥和排序后的参数拼接。响应数据采用AES-256-CBC加密,需使用特定Key和IV解密。文章详细介绍了签名生成规则、参数处理流程及加密常量定位方法,为接口对接提供了技术参考。整个过程展示了如何通过逆向工程还原前端加密逻辑,最终实现脱离浏览器环境的纯协议调用。

自成背后的博客 1174

Activity详解 Intent显式跳转和隐式跳转, 及多个Activity之间传值 总结

Activity 生命周期     显式 Intent 调用   1 //创建一个显式的 Intent 对象(方法一:在构造函数中指定) 2 Intent intent = new Intent(Intent_Demo1.this, Intent_Demo1_Result1.class); 3 4 Bundle bundle =

WILLIAM-HUAN 个人技术博客 1万+

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

[转]Activity详解 Intent显式跳转和隐式跳转

Activity 生命周期 显式 Intent 调用 1 //创建一个显式的 Intent 对象(方法一:在构造函数中指定) 2 Intent intent = new Intent(Intent_Demo1.this, Intent_Demo1_Result1.class); 3 4 ...

weixin_30783629的博客 121

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Activity详解 Intent显式跳转和隐式跳转, 及多个Activity之间传值 总 结

Activity 生命周期     显式 Intent 调用   1 //创建一个显式的 Intent 对象(方法一:在构造函数中指定) 2 Intent intent = new Intent(Intent_Demo1.this, Intent_Demo1_Result1.class); 3 4 Bundle bundle =

Never_Give_Up_Lin 692

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Activity之间跳转与传值

一、Activity跳转与传值,主要是通过Intent类来连接多个Activity,通过Bundle类来传递数据。 最常见最一般的页面跳转代码,很简单,如下:   Intent intent = new Intent(FirstActivity.this, SecondActivity.class);   startActivity(intent); 或者:    Intent inte

322

Android自动化测试进阶:使用ADB与Intent实现精准页面跳转与快捷方式调用

在移动应用测试领域,自动化测试是提升效率和保证质量的关键技术。其核心原理是通过脚本模拟用户操作,对应用功能进行验证。传统的UI自动化框架依赖于元素定位,但在页面动态变化或路径复杂时,稳定性和效率面临挑战。此时,ADB(Android调试桥)结合Intent机制展现出独特的技术价值,它允许测试脚本绕过UI层,直接与Android系统通信,实现精准的页面跳转和功能触发。这一方法特别适用于测试深层次页面、动态快捷方式以及需要预设复杂状态的场景,能显著提升测试用例的执行速度和稳定性。通过封装ADB命令并与主流测试框

weixin_34133829的博客 363

Android理解:显式和隐式Intent

Intent是Android初学者比较难理解的一个东西。我这里以通俗易懂的语言和通俗易懂的代码,让初学者简单感受一下Intent。 intent就是意图的意思。Intent分两种:显式(Explicit intent)和隐式(Implicit intent)。

叉叉哥的BLOG 4万+

Android开发:显式/隐式Intent意图跳转Activity总结

本文将详细介绍Android开发中如何使用intent跳转,包括使用intent调用系统应用

MichaelX的专栏 2万+

Activity跳转和Intent传值

多个Activity之间的调用 Intent显式调用 Intent隐式调用 使用Intent在Activity之间传递数据 直接使用Intent传递数据 使用Bundle传递数据 回传数据

简单点的博客 3417
上一篇: 菜单和上下文菜单的创建
下一篇: 自定义 Permmision 权限
aichangai9737
博客等级 码龄11年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值