我知道如何获得启动当前活动的意图,但我应该如何构建我的代码,以便如果用户从登录页面进入,则会发生一件事情,如果它们来自注册页面,则会发生另一件事情?
class Login extends Activity {
public final static String EXTRA_MESSAGE = "net.asdqwe.activities.Login.EXTRA_MESSAGE";
//code here
public void onClick(View arg0) {
Intent sendLoggedInUserToHomePage = new Intent(getApplicationContext(), Home.class);
sendLoggedInUserToHomePage.putExtra(EXTRA_MESSAGE,userEmailLoginPage);
startActivity(sendLoggedInUserToHomePage);
}
}
}
ASD
class Signup extends Activity {
public final static String EXTRA_MESSAGE = "net.asdqwe.activities.Signup.EXTRA_MESSAGE";
//code here
public void onClick(View arg0) {
Intent signupSuccessHome = new Intent(getApplicationContext(), Home.class);
signupSuccessHome.putExtra(EXTRA_MESSAGE, userEmail);
startActivity(signupSuccessHome);
}
}
现在我们在家里上课,我不知道该怎么做。 到目前为止,我只有注册页面,所以很容易:
Intent loggedInUser = getIntent();
userEmailId = loggedInUser.getStringExtra(Signup.EXTRA_MESSAGE);
userInfo = dbTools.getUserInfo(userEmailId);
但是,如果我还有来自Login的用户,我该如何更改此代码呢?
答案 0 :(得分:3)
在您的家庭班级中添加以下代码
String reqFrom = "";
Bundle b = this.getIntent().getExtras();
if (b != null)
reqFrom = b.getString("reqFrom");
if(reqFrom.equalsIgnoreCase("login")){
// some action
}
else {
// some other action
}
在您的登录页面中添加以下代码。
Intent sendLoggedInUserToHomePage = new Intent(getApplicationContext(), Home.class);
i.putExtra("reqFrom", "login");
startActivity(sendLoggedInUserToHomePage);