我希望用户通过我的登录要求才能登录

时间:2015-10-19 19:19:30

标签: java android-intent android-studio login

我希望仅在用户通过登录要求时才传递下面的意图。我试图在onClick监听器中放置一个if语句,但它没有用完。基本上,一旦用户名和密码符合我的要求,我想传递意图。如果意图没有通过,那么我想传递一个else语句,说“那个用户不存在。”

10-20 16:53:10.330 2138-2138/com.squarespace.atpublishing.officialworkoutapp 

I/art: Not late-enabling -Xcheck:jni (already on)
10-20 16:53:11.510 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 220ms
10-20 16:53:11.640 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 1555(94KB) AllocSpace objects, 0(0B) LOS objects, 33% free, 417KB/623KB, paused 0 total 130ms
10-20 16:53:11.850 2138-2138/com.squarespace.atpublishing.officialworkoutapp W/art: Verification of boolean android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu(int, android.view.Menu) took 170ms
10-20 16:53:11.850 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 130ms
10-20 16:53:12.780 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 80ms
10-20 16:53:13.660 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 30ms
10-20 16:53:13.900 2138-2150/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 10ms
10-20 16:53:13.900 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 1031(117KB) AllocSpace objects, 0(0B) LOS objects, 23% free, 781KB/1017KB, paused 10ms total 60ms
10-20 16:53:14.340 2138-2150/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 10ms
10-20 16:53:14.340 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 282(24KB) AllocSpace objects, 0(0B) LOS objects, 13% free, 878KB/1017KB, paused 10ms total 80ms
10-20 16:53:14.460 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background partial concurrent mark sweep GC freed 297(33KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 885KB/1397KB, paused 0 total 120ms
10-20 16:53:14.630 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms
10-20 16:53:14.900 2138-2229/com.squarespace.atpublishing.officialworkoutapp D/OpenGLRenderer: Render dirty regions requested: true
10-20 16:53:14.950 2138-2138/com.squarespace.atpublishing.officialworkoutapp D/: HostConnection::get() New Host Connection established 0x7fb36d6b8620, tid 2138
10-20 16:53:14.960 2138-2138/com.squarespace.atpublishing.officialworkoutapp D/Atlas: Validating map...
10-20 16:53:15.260 2138-2229/com.squarespace.atpublishing.officialworkoutapp D/: HostConnection::get() New Host Connection established 0x7fb36d6ec100, tid 2229
10-20 16:53:15.350 2138-2229/com.squarespace.atpublishing.officialworkoutapp I/OpenGLRenderer: Initialized EGL, version 1.4
10-20 16:53:15.430 2138-2229/com.squarespace.atpublishing.officialworkoutapp D/OpenGLRenderer: Enabling debug mode 0
10-20 16:53:15.440 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/EGL_emulation: eglSurfaceAttrib not implemented
10-20 16:53:15.440 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fb36d6b7b00, error=EGL_SUCCESS
10-20 16:53:15.620 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 30ms
10-20 16:53:15.650 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 39 frames!  The application may be doing too much work on its main thread.
10-20 16:53:20.900 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 40ms
10-20 16:53:20.930 2138-2150/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms
10-20 16:53:21.510 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 190ms
10-20 16:53:21.660 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 102 frames!  The application may be doing too much work on its main thread.
10-20 12:53:24.100 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 278(36KB) AllocSpace objects, 0(0B) LOS objects, 11% free, 1242KB/1397KB, paused 0 total 190ms
10-20 12:53:25.100 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 70ms
10-20 12:53:26.510 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 30ms
10-20 12:53:27.000 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms
10-20 12:53:27.330 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 149 frames!  The application may be doing too much work on its main thread.
10-20 12:53:27.770 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/EGL_emulation: eglSurfaceAttrib not implemented
10-20 12:53:27.770 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fb36d2e6900, error=EGL_SUCCESS
10-20 12:53:28.120 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 47 frames!  The application may be doing too much work on its main thread.
10-20 12:53:28.220 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/EGL_emulation: eglSurfaceAttrib not implemented
10-20 12:53:28.220 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fb36d2e69c0, error=EGL_SUCCESS
10-20 12:53:28.270 2138-2138/com.squarespace.atpublishing.officialworkoutapp W/View: requestLayout() improperly called by android.support.design.internal.NavigationMenuView{2c5956e4 VFED.VC. ......ID 0,0-384,800} during layout: running second layout pass
10-20 12:53:28.460 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms
10-20 12:53:29.040 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 38 frames!  The application may be doing too much work on its main thread.

`

      Button mEmailSignInButton = (Button)     
      findViewById(R.id.email_sign_in_button);

      mEmailSignInButton.setOnClickListener(new OnClickListener() {

        @Override


        public void onClick(View view) {

       attemptLogin();


if (mPasswordView.getText().toString().isEmpty() && mEmailSignInButton.getText().toString().isEmpty()){
                Snackbar.make(view, "You Didn't enter anything", Snackbar.LENGTH_LONG).setAction("Action", null);
            } else {
                Intent intent = new Intent(LoginActivity.this, DrawerActivity.class);
                startActivity(intent);
            }

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


 /**
 * Attempts to sign in or register the account specified by the login form.
 * If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual login attempt is made.
 */
private void attemptLogin() {
    if (mAuthTask != null) {
        return;
    }

    // Reset errors.
    mEmailView.setError(null);
    mPasswordView.setError(null);

    // Store values at the time of the login attempt.
    String email = mEmailView.getText().toString();
    String password = mPasswordView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password, if the user entered one.
    if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
        mPasswordView.setError(getString(R.string.error_invalid_password));
        focusView = mPasswordView;
        cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(email)) {
        mEmailView.setError(getString(R.string.error_field_required));
        focusView = mEmailView;
        cancel = true;
    } else if (!isEmailValid(email)) {
        mEmailView.setError(getString(R.string.error_invalid_email));
        focusView = mEmailView;
        cancel = true;
    }

    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        // Show a progress spinner, and kick off a background task to
        // perform the user login attempt.
        showProgress(true);
        mAuthTask = new UserLoginTask(email, password);
        mAuthTask.execute((Void) null)

    }
}

1 个答案:

答案 0 :(得分:0)

您的attemptLogin();需要在if的else {}内调用。

目前,它在您的if之前被调用,因此即使您的电子邮件或密码字段为空,它也会尝试登录。

这可能只是你的疏忽。如果没有,您可能希望通过在以下网站上进行练习来刷新Java。 http://codingbat.com/java