首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android中Bundle的运用示例

2012-09-23 
Android中Bundle的使用示例?xml version1.0 encodingutf-8? manifest xmlns:androidhttp://sch

Android中Bundle的使用示例

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
????? package="com.ray.test"
????? android:versionCode="1"
????? android:versionName="1.0">
??? <application android:icon="@drawable/icon" android:label="@string/app_name">
??????? <activity android:name=".TestBundle"
????????????????? 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=".Target"></activity>
??? </application>
??? <uses-sdk android:minSdkVersion="3" />
</manifest>

第一个活动的代码如下:

package com.ray.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;

public class TestBundle extends Activity {
??? public void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.main);
??? }
???
public boolean onTouchEvent(MotionEvent event) {
Intent intent = new Intent();
intent.setClass(TestBundle.this, Target.class);
Bundle mBundle = new Bundle();
mBundle.putString("Data", "ray'blog");//压入数据
intent.putExtras(mBundle);
startActivity(intent);
finish();
return super.onTouchEvent(event);
}
}

将要跳转到的活动代码:

package com.ray.test;

import android.app.Activity;
import android.os.Bundle;

public class Target extends Activity{
???
public void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.main);
??????? Bundle bundle = getIntent().getExtras();?
??????? String data=bundle.getString("Data");//读出数据
??????? setTitle(data);
??? }
}

热点排行