Pjr*_*111 1 java variables android android-2.2-froyo
假设我正在做类似测验的事情,我有一个计数器来显示已正确回答的问题数量.当一个问题得到正确回答,并显示一个新屏幕(活动)时,如何将该号码转移到下一个屏幕?
当你说屏幕时你的意思是活动?然后你可能想通过额外的意图传递它们.
活动1:
int score;
...
Intent Intent = new Intent(...);
intent.putExtra("score_key", score);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
活动2 onCreate():
int score;
...
Bundle extras = getIntent().getExtras();
// Read the extras data if it's available.
if (extras != null)
{
score = extras.getInt("score_key");
}
Run Code Online (Sandbox Code Playgroud)