登录后,登录活动不会继续进行下一个活动

问题描述 投票:-2回答:1

我创建了两个活动:一个用于登录,另一个用于导航抽屉。但是,当我登录时,它接受电子邮件和密码,但不会继续下一个活动,它显示应用程序已停止。

我的登录代码:

public class  LoginActivity extends AppCompatActivity implements    
View.OnClickListener {
private final AppCompatActivity activity = LoginActivity.this;

private NestedScrollView nestedScrollView;

private TextInputLayout textInputLayoutEmail;
private TextInputLayout textInputLayoutPassword;

private TextInputEditText textInputEditTextEmail;
private TextInputEditText textInputEditTextPassword;

private AppCompatButton appCompatButtonLogin;

private AppCompatTextView textViewLinkRegister;

private InputValidation inputValidation;
private DatabaseHelper databaseHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    getSupportActionBar().hide();

    initViews();
    initListeners();
    initObjects();
}

/**
 * This method is to initialize views
 */
private void initViews() {

    nestedScrollView = (NestedScrollView) findViewById(R.id.nestedScrollView);

    textInputLayoutEmail = (TextInputLayout) findViewById(R.id.textInputLayoutEmail);
    textInputLayoutPassword = (TextInputLayout) findViewById(R.id.textInputLayoutPassword);

    textInputEditTextEmail = (TextInputEditText) findViewById(R.id.textInputEditTextEmail);
    textInputEditTextPassword = (TextInputEditText) findViewById(R.id.textInputEditTextPassword);

    appCompatButtonLogin = (AppCompatButton) findViewById(R.id.appCompatButtonLogin);

    textViewLinkRegister = (AppCompatTextView) findViewById(R.id.textViewLinkRegister);

}

/**
 * This method is to initialize listeners
 */
private void initListeners() {
    appCompatButtonLogin.setOnClickListener(this);
    textViewLinkRegister.setOnClickListener(this);
}

/**
 * This method is to initialize objects to be used
 */
private void initObjects() {
    databaseHelper = new DatabaseHelper(activity);
    inputValidation = new InputValidation(activity);

}

/**
 * This implemented method is to listen the click on view
 *
 * @param v
 */
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.appCompatButtonLogin:
            verifyFromSQLite();
            break;
        case R.id.textViewLinkRegister:
            // Navigate to RegisterActivity
            Intent intentRegister = new Intent(getApplicationContext(), RegisterActivity.class);
            startActivity(intentRegister);
            break;
    }
}

/**
 * This method is to validate the input text fields and verify login credentials from SQLite
 */
private void verifyFromSQLite() {
    if (!inputValidation.isInputEditTextFilled(textInputEditTextEmail, textInputLayoutEmail, getString(R.string.error_message_email))) {
        return;
    }
    if (!inputValidation.isInputEditTextEmail(textInputEditTextEmail, textInputLayoutEmail, getString(R.string.error_message_email))) {
        return;
    }
    if (!inputValidation.isInputEditTextFilled(textInputEditTextPassword, textInputLayoutPassword, getString(R.string.error_message_email))) {
        return;
    }

    if (databaseHelper.checkUser(textInputEditTextEmail.getText().toString().trim()
            , textInputEditTextPassword.getText().toString().trim())) {

        Intent accountsIntent = newIntent(activity,NavigationDrawer.class);

        startActivity(accountsIntent);

    } else {
        // Snack Bar to show success message that record is wrong
        Snackbar.make(nestedScrollView, getString(R.string.error_valid_email_password), Snackbar.LENGTH_LONG).show();
    }
}

/**
 * This method is to empty all input edit text
 */
private void emptyInputEditText() {
    textInputEditTextEmail.setText(null);
    textInputEditTextPassword.setText(null);
    }
}

导航抽屉:

      public class NavigationDrawer extends Activity {
      private DrawerLayout mDrawerLayout;
      private ActionBarDrawerToggle nToggle;
      private ActionBar supportActionBar;

        @Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_drawer);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    nToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close);
    mDrawerLayout.addDrawerListener(nToggle);
    nToggle.syncState();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onOptionsItemSelected(MenuItem items){
    if(nToggle.onOptionsItemSelected(items)) {
        return true;
    }
        return super.onOptionsItemSelected(items);
    }

public ActionBar getSupportActionBar() {
    return supportActionBar;
}
}

}

我怎样才能解决这个问题?

android android-intent login android-navigation-drawer
1个回答
0
投票

有以下问题:

  1. 开发人员未在清单文件中初始化名称第二个活动。
  2. 在第二次活动中没有使用“this”获得getsupportActionBar()
© www.soinside.com 2019 - 2024. All rights reserved.