title: How can I display current user's name on display?
body: <p>After logging in, I want to display a message that says 'Welcome, (username)!' on the next activity. For now I have absolutely no idea how to implement it. So can somebody give me an advice?</p>
  
  <p>So far, I only managed to implement the signup &amp; login parts.</p>
  
  <p>Here are the code snippets that stores the user data and enable the login. </p>
  
  <ol>
  <li><p>MembershipDatabaseHelper.java</p>
  
  <pre><code>public final class MembershipDatabaseHelper extends SQLiteOpenHelper {
      private static final String DB_NAME = "members.db";
      private static final String DB_TABLE = "members";
      private static final int DB_VERSION = 1;
      private static final String COLUMN_ID = "_id";
      private static final String COLUMN_EMAIL = "email";
      private static final String COLUMN_FIRSTNAME = "firstname";
      private static final String COLUMN_LASTNAME = "lastname";
      private static final String COLUMN_PASSWORD = "password";
      private static final String COLUMN_DOB = "dob";
      private static final String CREATE_TABLE = "CREATE TABLE " + DB_TABLE + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, "
      + COLUMN_EMAIL + " TEXT NOT NULL, " + COLUMN_FIRSTNAME + " TEXT NOT NULL, " + COLUMN_LASTNAME + " TEXT NOT NULL, "
      + COLUMN_PASSWORD + " TEXT NOT NULL, " + COLUMN_DOB + " TEXT NOT NULL);";
  
      private static String queryDrop = "DROP TABLE IF EXISTS " + DB_TABLE;
  
      SQLiteDatabase db;
  
      public MembershipDatabaseHelper(Context context) {
          super(context, DB_NAME, null, DB_VERSION);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          db.execSQL(CREATE_TABLE);
          this.db = db;
      }
  
      public void signup(User user) {
          db = this.getWritableDatabase();
          ContentValues values = new ContentValues();
  
          String query = "SELECT * FROM " + DB_TABLE;
          Cursor cursor = db.rawQuery(query, null);
          int count = cursor.getCount();
  
          values.put(COLUMN_ID, count);
          values.put(COLUMN_EMAIL, user.getEmail());
          values.put(COLUMN_FIRSTNAME, user.getFirstname());
          values.put(COLUMN_LASTNAME, user.getLastname());
          values.put(COLUMN_PASSWORD, user.getPassword());
          values.put(COLUMN_DOB, user.getDob());
          db.insert(DB_TABLE, null, values);
          db.close();
      }
  
      public String searchPassword(String email) {
          db = this.getReadableDatabase();
          String query = "SELECT " + COLUMN_EMAIL + ", " + COLUMN_PASSWORD + " FROM " + DB_TABLE;
          Cursor cursor = db.rawQuery(query, null);
  
          String targetEmail;
          String password = "NOT FOUND";
  
          if(cursor.moveToFirst()) {
              do {
                  targetEmail = cursor.getString(0);
  
                  if(targetEmail.equals(email)) {
                      password = cursor.getString(1);
                      break;
                  }
              } while(cursor.moveToNext());
          }
          return password;
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          db.execSQL(queryDrop);
          this.onCreate(db);
      }
  }
  </code></pre></li>
  <li><p>And here is the login part.</p>
  
  <pre><code>public class LoginActivity extends Activity implements OnClickListener {
  
      Button login;
      EditText email, password;
      TextView signuphere;
      MembershipDatabaseHelper dbHelper = new MembershipDatabaseHelper(this);
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
  
          email = (EditText) findViewById(R.id.enter_email);
          password = (EditText) findViewById(R.id.enter_password);
          login = (Button) findViewById(R.id.login);
          signuphere = (TextView) findViewById(R.id.signuphere);
  
          login.setOnClickListener(this);
          signuphere.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View v) {
          switch(v.getId()) {
          case(R.id.login):
  
              String enteredEmail = email.getText().toString();
              String enteredPassword = password.getText().toString();
              String storedPassword = dbHelper.searchPassword(enteredEmail);
  
              if(enteredPassword.equals(storedPassword)) {
                  Toast.makeText(this, "Successfully logged in!", Toast.LENGTH_SHORT).show();
                  Intent intent = new Intent(LoginActivity.this, MainScreenActivity.class);
                  startActivity(intent);
                  finish();
              } else {
                  Toast.makeText(this, "Email and password don't match.", Toast.LENGTH_SHORT).show();
              }
              break;
  
          case(R.id.signuphere):
              startActivity(new Intent(this, SignupActivity.class));
              break;
          }
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
      }
  
      @Override
      public void onBackPressed() {
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setTitle("You haven't finished yet!").setMessage("Are you sure to quit?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  this.close();
              }
  
              private void close() {
                  finish();
              }   
          }).setNegativeButton("No", new DialogInterface.OnClickListener() {
  
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  dialog.cancel();    
              }
          });
  
          AlertDialog dialog = builder.create();
          dialog.show();
      }
  }
  </code></pre></li>
  </ol>