Tag: extra

在Android中使用Bundle代替直接Intent putExtra()的优点

在我的android应用程序中,我总是使用Intent类的putExtra()函数将任意数量的值传递给新的Activity 。 喜欢这个: Intent i = new Intent(this, MyActivity.class); i.putExtra(ID_EXTRA1, "1"); i.putExtra(ID_EXTRA2, "111"); startActivity(i); 我知道Android中的Bundle ,我也看到有人使用Bundle将值传递给新的Activity 。 喜欢这个: Intent intent = new Intent(this, MyActivity.class); Bundle extras = new Bundle(); extras.putString("EXTRA_USERNAME","my_username"); extras.putString("EXTRA_PASSWORD","my_password"); intent.putExtras(extras); startActivity(intent); 这里我有2个疑问。 为什么我应该使用Bundle如果我可以通过将值直接传递给Intent来将值传递给新的Activity ? 使用Bundle而不是直接的Intent putExtra()什么putExtra() ?