摘要:Activity 之間的切換
1. 透過Intent將資料傳遞到另一個Activity。
將 Bundle 資料背在 Intent 上,帶到Activity2。
Activity1.java
Bundle bundle = new Bundle();
bundle.putString("KEY1","HelloActivity1");
Intent intent = new Intent(Main.this, Activity2.class);
intent.putExtras(bundle);
startActivity(intent);
2. 透過Intent將資料傳遞到另一個Activity。
在Activity2 可以透過 this.getIntent()取得 Intent,接著利用getExtras 取得背在上面的Bundle資料。
Intent intent=this.getIntent();
Bundle bundle =intent.getExtras();
bundle.getString("KEY1");