我有一个小型应用程序,它从我的主应用程序活动中启动“登录”活动作为子活动。登录活动使用 EditText 字段收集用户名和密码,然后在单击提交按钮后将凭据发送到主活动进行验证。但由于某种原因,我的 onActivityResult() 不起作用。我什至尝试包含一个 TextView,我将在该方法的不同点进行操作以推断出它出错的地方,但似乎该方法本身由于某种原因没有执行。任何帮助将非常感激。
我的主要活动:
public class MainActivity extends Activity {
private final String userName = "9590778";
private final String userPass = "1234567";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void activity_about(View view){
Intent aboutIntent = new Intent(this, AboutActivity.class);
startActivity(aboutIntent);
}
public void activity_login(View view){
Intent loginIntent = new Intent(this, LoginActivity.class);
startActivityForResult(loginIntent, LoginActivity.LOGIN_REQUEST);
}
public void OnActivityResult(int requestCode, int responseCode, Intent resultIntent){
String passedUser;
String passedPass;
Intent intent = getIntent();
TextView lblTest = (TextView)findViewById(R.id.lblTest);
lblTest.setText("ATLEAST THIS IS WORKING!"); //THIS IS WHERE I AM TRYING TO MANIPULATE THE TEXTVIEW TO SEE IF METHOD IS EXECUTING!
if(requestCode == LoginActivity.LOGIN_REQUEST){
passedUser = intent.getStringExtra("PASSED_USER");
passedPass = intent.getStringExtra("PASSED_PASS");
if(passedUser.equals(userName)){
if(passedPass.equals(userPass)){
lblTest.setText("LOGIN SUCCESSFUL!");
}
}
else{
lblTest.setText("ACCESS DENIED!");
}
}
}
}
另外,这是我的登录活动:
public class LoginActivity extends Activity {
public static final int LOGIN_REQUEST = 9999;
public static final int LOGIN_RESPONSE = 1234;
private String passedUser;
private String passedPass;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_login, menu);
return true;
}
public void submitCred(View view){
Intent intent = getIntent();
EditText lblUser = (EditText)findViewById(R.id.txtUserName);
EditText lblPass = (EditText)findViewById(R.id.txtPassword);
passedUser = lblUser.getText().toString();
passedPass = lblPass.getText().toString();
intent.putExtra("PASSED_USER", passedUser);
intent.putExtra("PASSED_PASS", passedPass);
setResult(LOGIN_RESPONSE, intent);
finish();
}
}