1、Intent是Android程序中各组件之间交互的重要方式,一般可用于启动活动、启动服务、以及发送广播等场景,这里先对活动进行说明Intent的一些作用。

2、Intent的用法大致可分为,显式Intent和隐式Intent,本文针对显示的Intent进行简单的说明。

3、Intent有多个构造函数的重载,其中一个是Intent(Context packageContext,Class<?>cls)。这个构造函数有两个参数,第一个参数Context要求提供一个启动活动的上下文,第二个参数Class则是制定要启动的目标活动。通过这个构造函数可以构建出Intent的意图,然后用Activity类中提供了一个startActivity()的方法。举例如下:

新建项目myIntent,添加secondActivity类,里面添加代码:

public class secondActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.two_activity);
} }

同时添加一个two_activity.xml文件。添加一个一个按钮,

 <Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Welcome"/>

在activity_main.xml添加一个跳转按钮:

    <Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click me"/>

最后在MainActivity.java中添加单击setOnClickListener()方法:

public class MainActivity extends Activity {

	private Button btn1;

	@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); btn1=(Button)findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent(MainActivity.this,secondActivity.class);
startActivity(intent);
}
});
} }

这时候在手机上查看应用会发现无法跳转到第二个活动,问题在于,每一个活动都需要在AndroidManifest.xml中进行注册,在AndroidManifest.xml的<application></application>添加<activity android:name=".secondActivity"></activity>保存后继续运行即可。

安卓Intent(显式)的更多相关文章

  1. android之intent显式,显式学习

    intent,意图 当从一个Activity到另一个Activity时调用,这里重点学习显式,隐式的使用 使用语句上的区别: 隐式意图:                 显式意图: setAction ...

  2. 安卓Intent(隐式)

    相对于显式Intent(明确指出了目标组件名称的Intent),隐式Intent,没有明确指出目标组件名称.显式Intent直接用组件的名称定义目标组件,这种方式很直接.但是由于开发人员往往并不清楚别 ...

  3. Android-----Intent中通过startActivity(Intent intent )显式启动新的Activity

    Intent:即意图,一般是用来启动新的Activity,按照启动方式分为两类:显式Intent 和 隐式Intent 显示Intent就是直接以“类名称”来指定要启动哪一个Activity:Inte ...

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

    Activity 生命周期             显式 Intent 调用          1     //创建一个显式的 Intent 对象(方法一:在构造函数中指定)  2      Inte ...

  5. (转载)Android理解:显式和隐式Intent

    Intent分两种:显式(Explicit intent)和隐式(Implicit intent). 一.显式(设置Component) 显式,即直接指定需要打开的activity对应的类. 以下多种 ...

  6. 第五篇-以显式意图(Explicit Intent)跳往其它Activity

    此项目基于第四篇. Intent(意图) Explicit Intent(显式意图): 清楚指明需要前往的Activity的名称 用于APP内部的连接 Inplicit Intent(隐式意图): 不 ...

  7. 第一行Kotlin系列(二)Intent隐式显式跳转及向下传值

    1.Intent显式跳转页面 val button5 = findViewById<Button>(R.id.mButton5) button5.setOnClickListener { ...

  8. 【转】Android理解:显式和隐式Intent---- try catch

    原文网址:http://blog.csdn.net/xiao__gui/article/details/11392987 Intent是Android初学者比较难理解的一个东西.我这里以通俗易懂的语言 ...

  9. 显式Intent和隐式Intent

    http://blog.csdn.net/qs_csu/article/details/7995966 对于明确指出了目标组件名称的Intent,我们称之为“显式Intent”. 对于没有明确指出目标 ...

随机推荐

  1. USACO3.42American Heritage(二叉树)

    已知中前 求后序 递归一下 有一些小细节 /* ID: shangca2 LANG: C++ TASK: heritage */ #include <iostream> #include& ...

  2. javascript时间、随机数

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. UVA_1025_A_Spy_in_the_Metro_(动态规划)

    描述 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  4. FusionCharts参数说明-----3D饼图属性(Pie3D.swf )

    animation 是否显示加载图表时的动画 palette 内置的图表样式,共5个 paletteColors 自定义图表元素颜色(为多个,如过过少会重复) showAboutMenuItem 右键 ...

  5. (转载)MySql按日期进行统计(前一天、本周、某一天)

    (转载)http://www.yovisun.com/mysql-date-statistics.html 在mysql数据库中,常常会遇到统计当天的内容.例如,在user表中,日期字段为:log_t ...

  6. Colour your Log4Net events in your RichTextBox zz

    You’re most probably here because you have already read my article How to watch your log through you ...

  7. python 零散记录(三) 格式化字符串 字符串相关方法

    使用 % 符号格式化字符串: """常用转换说明符:""" #%s: 按照str()方式转换 #%r: 按照repr()方式转换 #%d: ...

  8. HDOJ 1004题 Let the Balloon Rise strcmp()函数

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  9. windows下Qt5.1 for android开发环境配置(PS:Qt5.2出来了哈,稳定)

    说明:以下开发环境配置过程参考了这些文章: http://qt-project.org/wiki/building_qt-android_on_windows http://www.hyarm.com ...

  10. db2 identity列重置,reset/restart

    db2中可以对表中的某一个列创建identity列,用于自动填充值,某些情况下(比如删除数据后,需要从最小值开始,并不重复,那可以对标识列进行reset操作) 语法: ALTER TABLE < ...