Android Open Source - class_board_app Login Activity

From Project

Back to project page class_board_app.


The source code is released under:

GNU General Public License

If you think the Android project class_board_app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.parse.starter;
/*w  w  w  .ja  v a 2 s  .c  o  m*/
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.parse.LogInCallback;
import com.parse.ParseException;
import com.parse.ParseUser;

 * Activity which displays a login screen to the user, offering registration as well.
public class LoginActivity extends Activity {
  // UI references.
  private EditText usernameView;
  private EditText passwordView;

  protected void onCreate(Bundle savedInstanceState) {


    // Set up the login form.
    usernameView = (EditText) findViewById(;
    passwordView = (EditText) findViewById(;

    // Set up the submit button click handler
    findViewById( View.OnClickListener() {
      public void onClick(View view) {
        // Validate the log in data
        boolean validationError = false;
        StringBuilder validationErrorMessage =
            new StringBuilder(getResources().getString(R.string.error_intro));
        if (isEmpty(usernameView)) {
          validationError = true;
        if (isEmpty(passwordView)) {
          if (validationError) {
          validationError = true;

        // If there is a validation error, display the error
        if (validationError) {
          Toast.makeText(LoginActivity.this, validationErrorMessage.toString(), Toast.LENGTH_LONG)

        // Set up a progress dialog
        final ProgressDialog dlg = new ProgressDialog(LoginActivity.this);
        dlg.setTitle("Please wait.");
        dlg.setMessage("Logging in.  Please wait.");;
        // Call the Parse login method
        ParseUser.logInInBackground(usernameView.getText().toString(), passwordView.getText()
            .toString(), new LogInCallback() {

          public void done(ParseUser user, ParseException e) {
            if (e != null) {
              // Show the error message
              Toast.makeText(LoginActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
            } else {
              // Start an intent for the dispatch activity
              Intent intent = new Intent(LoginActivity.this,RouteActivity.class);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

  private boolean isEmpty(EditText etText) {
    if (etText.getText().toString().trim().length() > 0) {
      return false;
    } else {
      return true;

Java Source Code List