main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Welcome to Cinrry's blog"
/>
<Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点击进入Layout2"
/>
</LinearLayout>
mylayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Here's tne intent Activity"
/>
<Button
android:id="@+id/bt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点击进入Layout1"
/>
</LinearLayout>
然后是控制程序IntentDemo.java 及IntentDemo1.java 代码:
IntentDemo.java:
package com.android.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class IntentDemo extends Activity {
private Button bt1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt1 = (Button)findViewById(R.id.bt1);
bt1.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
//new 一个Intent对象,并指定要启动的Class
Intent intent = new Intent();
intent.setClass(IntentDemo.this, IntentDemo1.class);
//调用一个新的Activity
startActivity(intent);
//关闭原本的Activity
IntentDemo.this.finish();
}
});
}
}
在IntentDemo.java 同一目录内新建一个IntentDemo1.java 类
IntentDemo1.java:
package com.android.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class IntentDemo1 extends Activity {
private Button bt2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 载入mylayout.xml
setContentView(R.layout.mylayout);
bt2 = (Button) findViewById(R.id.bt2);
bt2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// new 一个Intent对象,并指定要启动的Class
Intent intent = new Intent();
intent.setClass(IntentDemo1.this, IntentDemo.class);
// 调用一个新的Activity
startActivity(intent);
// 关闭原本的Activity
IntentDemo1.this.finish();
}
});
}
}
最后是本例子的重点,添加另外一个Activity 所以必须在AndroidManifest.xml 中定义一个新的activty ,并给予名称name ,或则程序无法编译运行.新手很容易遇到这个问题.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.test"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".IntentDemo"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="IntentDemo1"></activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
分享到:
相关推荐
android 利用intent调用activity 简明精炼的例子 传递数据,并且有返回值
使用Intent调用系统的相机服务 并把图片保存起来 显示到ImageView上 也可以打开本地的图片 欢迎下载 你绝对不吃亏
Android Intent调用 Uri的方法总结 //调用浏览器 Uri uri = Uri.parse(); Intent it = new Intent(Intent.ACTION_VIEW,uri); startActivity(it); //显示某个坐标在地图上 Uri uri = Uri.parse(geo:38.899533,-...
本文档记载了常用的几个系统组件的启动关键代码 action 和category data的值
主要介绍了Android 通过Intent调用系统拍照程序出现图片太小的问题解决办法的相关资料,需要的朋友可以参考下
SmartScanner Android API 用于便捷API,可简化Intent调用过程。 该库提供了可以用来启动对MRZ,条形码和卡的扫描的方法,而不是手动创建和调用意图的方法。 注意:在达到v1.0之前,库的API可能会不断发展,因此在...
详情参见http://blog.csdn.net/djl461260911/article/details/41328665
Android 用Intent调用系统中经常被用到的组件 android用于打开各种文件的intent
Intent 与 Intent Filters 实现外部调用
Android的静默安装似乎是一个很有趣很诱人的东西,但是,用普通做法,如果手机没有root权限的话,似乎很难实现静默安装,因为Android并不提供显示的Intent调用,一般是通过以下方式安装apk: Intent intent = new ...
Intent调用系统拨号
刚开始网上都说android不能通过蓝牙发送APK,系统做了限制。其实这只是针对普通用户而言,对开发者来说其实几行代码就能...通过intent调用。几行代码解决蓝牙连接、蓝牙发送文件。因为系统自带蓝牙发送文件的apk的。
程序说明 -------------------------------------------------------------------- 程序名称:小安任务助手(AndroidTaskAssistant) SDK版本号:2.2(兼容1.6, 2.1, 2.2) 软件版本:1.0.1 -----------------------...
Android代码示例——从相机或相册中获取图片,并调用系统自带截取功能,截取后保存并更换背景
android调用系统邮件组件 Intent匹配流程 csdn博客地址
intent直接调用,显式启动intent直接调用,显式启动intent直接调用,显式启动intent直接调用,显式启动
自己的应用A调用自己的应用B,有比较多的方法,例如,在被调用的应用B的Activity内,设置Intent-filter,然后直接使用Intent调用。这些后面再讲,本讲先讲如何调用第三方应用,例如:百度云盘。 调用第三方应用需要...
3.4.3 语音识别方法一:使用intent调用语音识别程序 80 3.4.4 语音识别方法二:应用程序自己调用语音识别库 82 3.4.5 语音识别方法三:使用Service调用语音识别程序 84 3.4.6 人脸识别 87 3.4.7 图像识别 89 3.4.8 ...