【发布时间】:2016-11-29 22:14:09
【问题描述】:
我试图将一个 int 变量从一个活动类 (A) 传递到另一个活动类 (B)。由于我是初学者,所以我被困在这里。
我尝试了很多方法,但是每次在调试模式下运行代码时,我都可以看到我传递给第二个类的 int 值变成了 0。
活动 A 的代码
public void startMainActivity(View view)
{
//Sending the semester value to Navdrawer
Intent intentsem = new Intent(LoginActivity.this, NavDrawer.class);
intentsem.putExtra("UserSemester", usersemester);
startActivity(intentsem);
//Sending the branch value to Navdrawer
Intent intentbranch= new Intent(LoginActivity.this, NavDrawer.class);
intentbranch.putExtra("UserBranch", userbranch);
startActivity(intentbranch);
}
活动 B 的代码
public void startSyllabusactivity(View view)
{
// for first year
int semester = getIntent().getIntExtra("UserSemester", 0);
if (semester==1 || semester==2) {
Intent l = new Intent(this, firstyear_syllabussubject_selector.class);
startActivity(l);
}
//rest of the actions with branches to be added***********************
}
【问题讨论】:
-
您能否将代码也发布给我们,以便我们找到您的确切问题。
-
你有没有使用意图?