android之隐式intent调用
直接上代码
MainActivity.java
1 package com.example.test1; 2 3 import android.app.Activity; 4 import android.content.Intent; 5 import android.net.Uri; 6 import android.os.Bundle; 7 import android.view.View; 8 import android.view.View.OnClickListener; 9 import android.widget.Button; 10 11 public class MainActivity extends Activity { 12 13 @Override 14 protected void onCreate(Bundle savedInstanceState) { 15 super.onCreate(savedInstanceState); 16 setContentView(R.layout.activity_main); 17 18 Button btnButton = (Button) findViewById(R.id.button1); 19 20 btnButton.setOnClickListener(new OnClickListener() { 21 22 @Override 23 public void onClick(View v) { 24 // TODO Auto-generated method stub 25 Intent intent = new Intent(); 26 intent.setAction("aa.bb.cc.dd.ee.ff"); 27 28 startActivity(intent); 29 } 30 }); 31 } 32 }
SecondActivity.java
1 package com.example.test1; 2 3 import android.app.Activity; 4 import android.content.Intent; 5 import android.os.Bundle; 6 import android.widget.TextView; 7 8 public class SecondActivity extends Activity { 9 10 @Override 11 protected void onCreate(Bundle savedInstanceState) { 12 13 super.onCreate(savedInstanceState); 14 15 setContentView(R.layout.second_main); 16 17 Intent intent = getIntent(); 18 19 TextView textView = (TextView) findViewById(R.id.textView1); 20 textView.setText(intent.getAction()); 21 } 22 }
activity_main.xml
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:paddingBottom="@dimen/activity_vertical_margin" 6 android:paddingLeft="@dimen/activity_horizontal_margin" 7 android:paddingRight="@dimen/activity_horizontal_margin" 8 android:paddingTop="@dimen/activity_vertical_margin" 9 tools:context=".MainActivity" > 10 11 <Button 12 android:id="@+id/button1" 13 android:layout_width="wrap_content" 14 android:layout_height="wrap_content" 15 android:layout_alignParentTop="true" 16 android:layout_centerHorizontal="true" 17 android:layout_marginTop="124dp" 18 android:text="跳转" /> 19 20 </RelativeLayout>
second_main.xml
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 > 6 7 <TextView 8 android:id="@+id/textView1" 9 android:layout_width="wrap_content" 10 android:layout_height="wrap_content" 11 android:layout_alignParentLeft="true" 12 android:layout_alignParentTop="true" 13 android:layout_marginLeft="93dp" 14 android:layout_marginTop="176dp" 15 android:text="Large Text" 16 android:textAppearance="?android:attr/textAppearanceLarge" /> 17 18 </RelativeLayout>
很重要的AndroidManifest.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example.test1" 4 android:versionCode="1" 5 android:versionName="1.0" > 6 7 <uses-sdk 8 android:minSdkVersion="8" 9 android:targetSdkVersion="17" /> 10 11 <application 12 android:allowBackup="true" 13 android:icon="@drawable/ic_launcher" 14 android:label="@string/app_name" 15 android:theme="@style/AppTheme" > 16 <activity 17 android:name="com.example.test1.MainActivity" 18 android:label="@string/app_name" > 19 <intent-filter> 20 <action android:name="android.intent.action.MAIN" /> 21 22 <category android:name="android.intent.category.LAUNCHER" /> 23 </intent-filter> 24 </activity> 25 <activity android:name="com.example.test1.SecondActivity"> 26 <intent-filter> 27 <action android:name="aa.bb.cc.dd.ee.ff"/> 28 29 <category android:name="android.intent.category.DEFAULT" />//隐式intent调用,这句必须加 30 </intent-filter> 31 </activity> 32 33 </application> 34 35 </manifest>
转载于:https://www.cnblogs.com/ziyouchutuwenwu/archive/2013/05/24/3097153.html
android之隐式intent调用相关推荐
- Android Intent常用方法详细介绍,显示Intent,隐式Intent,调用浏览器,拨号,发短信,传递数据
Intent介绍 Intent是Android程序中各个组件之间进行交互的一种重要方式,它不仅可以指明当前组件想要执行的动作,还可以在不同组件之间传递数据.Intent一般用于启动活动,启动服务以及发 ...
- Android Studio App开发入门之在活动之间传递消息(附源码 超详细必看)(包括显示和隐式Intent,向上一个和下一个Activity发送数据)
运行有问题或需要源码请点赞关注收藏后评论区留言~~ 显示Intent和隐式Intent Intent是各个组件之间的信息沟通的桥梁,既能在Activity之间沟通,又能在Activity与Servi ...
- Android学习-Kotlin语言入门-变量、函数、语法糖、when、for-in、主构造函数、单例类、函数式API、集合遍历、隐式Intent、Activity生命周期、四种启动模式、标准函数
探究java语言的运行机制 变量.函数.语法糖 when条件语句 for循环 主构造函数.次构造函数 数据类和单例类 集合的创建与遍历 集合的函数式API 创建菜单 隐式使用Intent Activi ...
- Android编程权威指南(第15章 隐式intent)
15.1 1.添加按钮用字符串(Strings.xml) <string name="crime_report_subject">CriminalIntent Crim ...
- 使用隐式Intent打开系统浏览器的百度网页
使用隐式Intent,我们不仅可以启动自己程序内的活动,还可以启动其它程序的活动,这使得Android多个应用程序之间的功能共享成为了可能.比如说你的应用程序中需要展示一个网页,这时你没有必要自己去实 ...
- 显式Intent 和隐式 Intent 的区别
显式 Intent : 在知道目标组件名称的前提下,去调用Intent.setComponent().Intent.setClassName()或Intent.setClass()方法或者在new I ...
- 新手求助,关于添加隐式intent程序崩溃问题
新手一枚,刚开始学Android开发,最近在学隐式intent,发现加入后不报错但是运行后系统崩溃,有木有大神愿意指导一下,感激不尽. 以下为日志信息: 12-04 14:07:33.871: E/A ...
- Android的隐式意图
Android的隐式意图 对于隐式意图,Android是怎样寻找到这个最合适的组件呢?记的前面我们在定义活动时,指定了一个intent-filter,Intent Filter(意图过滤器)其实就是用 ...
- 显式Intent与隐式Intent
1.显式Intent(explicit intent) 显式Intent明确指定了要启动的activity: Intent intent= new Intent(this, Target.class) ...
最新文章
- 冒泡排序讲的明白 也有代码的
- 2022年跨境电商的风口还在吗?
- 闷热夏日这个空调太疯狂!
- 前端学习(219):css伪类选择器
- 收藏 | PyTorch 单机多卡操作总结
- centos7配置静态ip地址
- C 标准库 —— stdio.h
- java jtree怎么初始化,java – 如何设置JTree“ctrl”选择模式始终启用
- border-radius几种写法的原理剖析
- AWS redshift-hdb pg(Greenplum), 内置函数、数据类型、字符集
- 进位位判别法_''进位-判断-执行''的通用思想
- 各个版本的ArcGis集合下载
- 【Kay】MySQL必会常用函数
- IP协议(IP协议报头、MTU、网段划分、NAT技术、路由的工作过程)
- S@Kura的PHP进阶之路(五)
- 新款自助机存在的故障隐患及解决方法
- 【Matlab】多元线性回归(Excel可直接替换数据)
- MATLAB离散卷积的实现_代码编写_实现两列数的卷积
- internship:数据库表和建立的实体类及对应的枚举类之间的联系示例
- 拒绝成为比尔·盖茨的“万维网之父”,又要干大事!
热门文章
- Java Web Servlet
- 比特币到底是不是货币?
- Java zip解压,并遍历zip中的配置文件 .cfg或.properties
- InnoDB引擎与MyIASM的一点总结
- Linux运维系统工程师系列---13
- PHP的session阻塞问题
- 实现 IE6 支持 position fixed 的 CSS 属性
- Jm86中的encode_one_macroblock注释
- java流的传递方式是_如何在方法中流式传输Java List(Varargs)的值?
- python地理可视化_【Python教程】地理可视化之二