Android 台灣中文網
標題:
Intent 與 Bundle簡易運用
[打印本頁]
作者:
xyaw
時間:
2013-8-1 10:22
標題:
Intent 與 Bundle簡易運用
兩個不同Activity之間的資料傳遞
可以透過Intent 與 Bundle搭配的方法來做
傳送資料的程式碼:
public void nextview(View view)
{
Intent ihtent=new Intent();
ihtent.setClass(this, report_app2.class);
Bundle ibundle=new Bundle();
EditText editText_name1=(EditText)findViewById(R.id.editText_name);
ibundle.putString("editText_name", editText_name1.getText().toString());
ihtent.putExtras(ibundle);
startActivity(ihtent);
MainActivity.this.finish();
}
接收部分的程式碼:
TextView textView3=(TextView)findViewById(R.id.textView2);
Bundle receive_bundle1=this.getIntent().getExtras();
textView3.setText(receive_bundle1.getString("editText_name"));
有興趣的話可以這邊下載範例程式來試試
http://guangyaw.blogspot.tw/2013/07/android-intent-bundle.html
作者:
whl
時間:
2013-8-1 22:40
Good,很棒的基本功,不過要記住,傳送資料會有長度限制喔。
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1