0

我知道如何获得启动当前活动的意图,但是我应该如何构建我的代码,以便如果用户从登录页面进入,会发生一件事,如果他们来自注册页面,则会发生另一件事?

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);

但是既然我也有来自登录的用户,我该如何更改此代码?

4

1 回答 1

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);
于 2013-10-06T15:52:12.227 回答