Android学习笔记02——Intent的使用
来源:互联网 发布:数据库开发是做什么的 编辑:程序博客网 时间:2024/06/01 18:34
Android学习笔记02——Intent的使用
学习内容:
创建Activity的要点:
1.一个Activity就是一个类,并且该类继承自Activity
2.需要覆写onCreate方法
.每一个Activity都需要在AndroidMainfest.xml文件当中进行配置
4.为每一个Activity添加必要的控件
Intent的使用一个Intent对象包含了一组信息:
Componentname :要启动的对象,如Activity,service等
Action :指定对象的动作(详见下图)
Data :类型
Category :
Extras :“键值对”
Flags :
注:Intent可以在不同程序中的两个Activity传递信息
演示效果:
相关代码:
intentActivity.java
package wml.android.intentActivity;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class IntentActivityActivity extends Activity { /** Called when the activity is first created. */private Button myBut=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myBut=(Button)findViewById(R.id.but);//添加监听器 myBut.setOnClickListener(new MyButtonListener()); } class MyButtonListener implements OnClickListener{public void onClick(View v) {// TODO Auto-generated method stubIntent intent=new Intent();//创建Intent对象intent.setClass(IntentActivityActivity.this, OtherActivity.class); //实现从本Activity到OtherActivity的跳转 IntentActivityActivity.this.startActivity(intent);//Activity通过intent启动OtherActivity} }}
OtherActivity :
package wml.android.intentActivity;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class OtherActivity extends Activity{private TextView myTextView=null;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.other);myTextView=(TextView)findViewById(R.id.othertext);}}
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffff0000" android:orientation="vertical" > <TextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="40px" android:text="练习使用intent对象" /> <Button android:id="@+id/but" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="点我" /></LinearLayout>
other.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#fff00fff" android:orientation="vertical" > <TextView android:id="@+id/othertext" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="30px" android:text="我是被intent唤出的Activity 成功!" /></LinearLayout>
string.xml
string.xml<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World, IntentActivityActivity!</string> <string name="app_name">第二个Activity、</string> <string name="other">第二个Activity</string></resources>
需要配置AndroidManiFest.xml文件(加粗字为添加的代码)
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="wml.android.intentActivity" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".IntentActivityActivity" 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" > </activity> </application></manifest>
- Android学习笔记02——Intent的使用
- 隐式Intent的使用——Android学习笔记3
- Android学习笔记--3.Intent的使用
- android学习笔记——使用Intent传递对象
- Android学习笔记(九)—— 调用另外一个Activity — Intent对象的使用
- Android学习笔记(4)-学习Intent的使用
- Android学习笔记(4)-学习Intent的使用
- Android学习笔记-学习Intent的使用
- River的Android学习笔记——Intent意图
- android学习笔记——Intent
- android学习笔记——intent
- android学习笔记1——Intent
- Android学习笔记——Intent
- Android 开发笔记—— Intent的使用
- android笔记6——intent的使用
- android学习笔记——Intent的解析(Intent的隐式调用)
- Android学习笔记7——Intent和Intent Filters的介绍
- Android学习笔记----使用Intent传递对象
- 工厂方法与抽象工厂的区别
- C标准函数篇
- git使用问题
- 类和对象深入讨论——指向类的成员的指针
- sizeof()与strlen()的区别
- Android学习笔记02——Intent的使用
- 基于FPGA的跨时钟域信号处理——MCU
- 串口操作类
- Oracle 起步日记(7)——触发器
- Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)的用法
- IOS学习笔记 — UITextField 输入完毕关闭键盘方法
- WM/WinCE 下访问Sqlite的Native C++封装 (CppSQLite3U的使用)
- 用 Graphviz 可视化函数调用
- fedora16 设置 gedit软件的默认编码