在登录活动中,意图无效

时间:2014-05-02 11:04:04

标签: android android-intent android-activity

在此活动中,当密码和用户名都正确时,我已经显示了一个toast并且意图在登录后移动到下一个屏幕,但只有toast有效,意图不起作用?

btnSignIn.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // get The User name and Password
        String userName = editTextUserName.getText().toString();
        String password = editTextPassword.getText().toString();

        // fetch the Password form database for respective user name
        String storedPassword = loginDataBaseAdapter.getSinlgeEntry(userName);

        // check if the Stored password matches with Password entered by
        // user
        if (password.equals(storedPassword)) {
            Toast.makeText(HomeActivity.this, "Congrats: Login Successfull",
                    Toast.LENGTH_LONG).show();
            dialog.dismiss();
            Intent intent = new Intent(getApplicationContext(), ViewFolders.class);
            startActivity(intent);

        } else {
            Toast.makeText(HomeActivity.this, "User Name or Password does not match",
                    Toast.LENGTH_LONG).show();
        }
    }
});

登录后,它不会转移到ViewFolders.class

3 个答案:

答案 0 :(得分:0)

尝试以下:

Intent intent=new Intent(YOUR ACTIVITY.this,ViewFolders.class);
startActivity(intent);

答案 1 :(得分:0)

试试此代码

Intent intent=new Intent(LoginActivity.this,ViewFolders.class); 
startActivity(intent);

并在此解释 difference and when to use getApplication(), getApplicationContext(), getBaseContext() and someClass.this

答案 2 :(得分:0)

使用:

Intent intent=new Intent(HomeActivity.this,ViewFolders.class);
startActivity(intent);

而不是:

Intent intent=new Intent(getApplicationContext(),ViewFolders.class);
startActivity(intent);

此希望ViewFolders活动已添加到已显示