27.02.2014 Views

Android 开发教程

Android 开发教程

Android 开发教程

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

-----------------------------------<strong>Android</strong> 编 程 基 础<br />

<strong>Android</strong> 应 用 开 发 3<br />

使 用 Bundle 在 Activity 间 传 递 数 据<br />

从 源 Activity 中 传 递 数 据<br />

// 数 据 写 入 Intent<br />

Intent openWelcomeActivityIntent=new<br />

new Intent();<br />

Bundle myBundelForName=new<br />

new Bundle();<br />

myBundelForName.putString("Key_Name",inName.getText().toString());<br />

myBundelForName.putString("Key_Age",inAge.getText().toString());<br />

openWelcomeActivityIntent.putExtras(myBundelForName);<br />

openWelcomeActivityIntent.setClass(<strong>Android</strong>Bundel.this<br />

this, Welcome.class<br />

class);<br />

startActivity(openWelcomeActivityIntent);<br />

目 标 Activity 中 获 取 数 据<br />

// 从 Intent 中 获 取 数 据<br />

Bundle myBundelForGetName=this<br />

this.getIntent().getExtras();<br />

String name=myBundelForGetName.getString("Key_Name");<br />

myTextView_showName.setText(" 欢 迎 您 进 入 :"+name);<br />

使 用 Bundle 在 Activity 间 传 递 数 据 2<br />

从 源 请 求 Activity 中 通 过 一 个 Intent 把 一 个 服 务 请 求 传 到 目 标 Activity 中<br />

private Intent toNextIntent;//Intent 成 员 声 明<br />

toNextIntent=new<br />

new Intent();//Intent 定 义<br />

toNextIntent.setClass(TwoActivityME3.this<br />

this, SecondActivity3.class<br />

class);<br />

// 设 定 开 启 的 下 一 个 Activity<br />

startActivityForResult(toNextIntent, REQUEST_ASK);<br />

// 开 启 Intent 时 候 , 把 请 求 码 同 时 传 递<br />

2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!