私のAndroidアプリケーションでは、クラスの直接putExtra()
関数を常に使用しIntent
て、任意の数の値を new に渡していますActivity
。
このような:
Intent i = new Intent(this, MyActivity.class);
i.putExtra(ID_EXTRA1, "1");
i.putExtra(ID_EXTRA2, "111");
startActivity(i);
私は Android について知っており、値を new に渡すために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点疑問があります。newに値を直接渡すことで値を渡すことができる場合、
なぜ使用する必要があるのですか? direct の代わりに
使用する利点は何ですか?Bundle
Activity
Intent
Bundle
Intent
putExtra()