Activity和Intent
Activity02
package org.wp.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Activity02 extends Activity {
private Button myButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton = (Button) findViewById(R.id.myButton);
myButton.setText("Next");
myButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent();
intent.putExtra("name", "张三");
intent.setClass(Activity02.this, OtherActivity.class);
startActivity(intent);
}
});
}
}
OtherActivity
package org.wp.activity;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class OtherActivity extends Activity {
private TextView myTextView;
private Button otherButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
Intent intent = getIntent();
String value = intent.getStringExtra("name");
myTextView = (TextView) findViewById(R.id.myTextView);
otherButton = (Button) findViewById(R.id.otherButton);
myTextView.setText(value);
otherButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Uri uri = Uri.parse("smsto://080000123");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", "The SMS Text");
startActivity(intent);
}
});
}
}
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"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myButton"
/>
</LinearLayout>
other.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:id="@+id/myTextView"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/otherButton"
android:id="@+id/otherButton"
/>
</LinearLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Activity02!</string>
<string name="app_name">Activity02</string>
<string name="other">OtherActivity</string>
<string name="otherButton">发送短信</string>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.wp.activity" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Activity02" 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=".OtherActivity" android:label="@string/other" />
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
分享到:
相关推荐
通常 Android会根据Intent 中包含的其它属性的信息,比如action、data/type、category进行查找,最终找到一个与之匹配的目标组件。但是,如果 component这个属性有指定的话,将直接使用它指定的组件,而不再执行上述...
Android期末复习总结,用于期末复习、课后题源自学校发的教材。 部分内容: Android架构层: Linux内核层(LinuxKernel) 系统运行时库层(Libraries和 AndroidRuntime) 应用程序架构层(ApplicationFramework) 应用...
第四章:管理Android系统桌面 31 一、 管理壁纸 31 二、 管理快捷方式 33 三、 管理桌面控件 34 第五章:传感器开发 37 一、 传感器概述 37 二、 常用传感器 39 第六章:GPS应用开发 41 一、 支持GPS的核心API 41 二...
自己总结的Android校招面试复习资料,包含:J2SE基础、Android基础、数据结构与算法、计算机网络、操作系统。
2.Android 中下列属于Intent的作用的是( ) A、实现应用程序间的数据共享 B、是一段长的生命周期,没有用户界面的程序,可以保持应用在后台运行,而不会因为切换页面而消失 C、可以实现界面间的切换,可以包含动作和...
太原理工大学2015安卓 考试题库 就是一些安卓面试题
android 复习知识 便于大家复习备考
安卓android期末考试复习要点.docx
为了那些新手更了解android,android很目前还不错。好好学习吧
android复习大纲 便于大家知道该复习的内容
android复习题纲 a)掌握Android的常用布局: b)掌握Android的事件处理方式:基于监听(五种使用方法)和基于回调,以及Handler的用法 c)掌握系统基本服务的使用,包括拨打电话、发送短信、添加联系人、调节音量、...
android 开发,基础复习。Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机。
Android复习题 .docx
大学期末考试:Android最新复习重点
Android开发复习总结,个人总结的一些资料。Android 教程 Android是一个开源的,基于Linux的移动设备操作系统,主要使用于移动设备,如智能手机和平板电脑。Android是由谷歌及其他公司带领的开放手机联盟开发的
Android 四大组件 选择题 选择题 1. 下面不是Android四大组件之一的( B ) A. Activity B.Intent C. Service D. ContentProvider 2. 下面关于广播叙述错误的是(A) A. 广播是Android四大组件之一 B. ...
Android复习题.doc
共享这份android考试复习资料,希望对大家的学习有帮助。
android考试复习题.pdfandroid考试复习题.pdfandroid考试复习题.pdfandroid考试复习题.pdfandroid考试复习题.pdf
android复习资料