im new to android dev.
I start by follow some tutorial and i make a simple app.
I'm confused to the way start other activity
.
I have 3 activity login
, main
, temp
when i at main activity
i want to start temp activity
by the code below:
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
Intent nextIntent;
switch (id){
case R.id.item1:
nextIntent = new Intent(MainActivity.this, TempActivity.class);
startActivity(nextIntent);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
break;
case R.id.item2:
nextIntent = new Intent(MainActivity.this, TempActivity.class);
startActivity(nextIntent);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
break;
case R.id.item3:
nextIntent = new Intent(MainActivity.this, TempActivity.class);
startActivity(nextIntent);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
break;
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
and i did the same in login activity
but not working:
private void login() {
Log.d(TAG, "Login");
_loginButton.setEnabled(false);
//show spinner
final ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this,
R.style.AppTheme_Dark_Dialog);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Authenticating...");
progressDialog.show();
// TODO: Implement your own authentication logic here.
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
// On complete call either onLoginSuccess or onLoginFailed
onLoginSuccess();
// onLoginFailed();
progressDialog.dismiss();
}
}, 3000);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == requestCode) {
if (resultCode == RESULT_OK) {
// TODO: Implement successful signup logic here
// By default we just finish the Activity and log them in automatically
startActivity(new Intent(this, MainActivity.class));
this.finish();
}
}
}
public void onLoginSuccess() {
//do nothing
finish();
}
instead i have to do this:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == requestCode) {
if (resultCode == RESULT_OK) {
// TODO: Implement successful signup logic here
// By default we just finish the Activity and log them in automatically
this.finish();
}
}
}
public void onLoginSuccess() {
startActivity(new Intent(this, MainActivity.class));
setResult(RESULT_OK);
finish();
}
and why requestCode == requestCode
i couldn't find function setRequestCode
like setResultCode
last question: should I use fragment
instead of activity
to share my NavigationBar
because now i have to include navigationBar
layout to tempActivity
layout, and same java code
in class