我正在开发一个 Android 应用程序,但我不知道该怎么做。
我有一个 Dog 类的实例。这个类有两个属性isMale
和Id
(和另一个)。
如果我将这两个属性传递给另一个Activity
:
public void onAddClick(View view)
{
if (mSelectedDog == null)
// TODO: Show a message to indicate that or maybe, the button add could be disabled.
;
else
{
Intent intent = new Intent(this, AddDogActivity.class);
// Pass to AddDogActivity if we are going to add a male or female dog.
Bundle b = new Bundle();
// Pass dog's sex.
b.putBoolean(Constants.ACT_ADD_DOG_IS_A_MALE, mSelectedDog.isMale());
// Pass dog's id
b.putInt(Constants.ACT_ADD_DOG_ID, mSelectedDog.getId());
intent.putExtras(b);
// TODO: Maybe it is better pass Dog instance instead of isMale and ID.
startActivity(intent);
}
}
我需要Dog
在AddDogActivity
.
传递这两个属性或传递mSelectedDog
给哪个更好AddDogActivity
?