Android Open Source - PromenadeAndroid Register Activity

From Project

Back to project page PromenadeAndroid.


The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project PromenadeAndroid 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.promenadevt;
 /*from  w  ww  . j a  va  2 s.  c om*/
import org.json.JSONException;
import org.json.JSONObject;
import com.promenadevt.library.DatabaseHandler;
import com.promenadevt.library.UserFunctions;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class RegisterActivity extends Activity {
    Button btnRegister;
    Button btnLinkToLogin;
    EditText inputFullName;
    EditText inputEmail;
    EditText inputPassword;
    TextView registerErrorMsg;
    // JSON Response node names
    private static String KEY_SUCCESS = "success";
    private static String KEY_ERROR = "error";
    private static String KEY_ERROR_MSG = "error_msg";
    private static String KEY_PASS = "pass";
    private static String KEY_NAME = "name";
    private static String KEY_EMAIL = "email";
    private static String KEY_CREATED_AT = "created_at";
    public void onCreate(Bundle savedInstanceState) {
        // Importing all assets like buttons, text fields
        inputFullName = (EditText) findViewById(;
        inputEmail = (EditText) findViewById(;
        inputPassword = (EditText) findViewById(;
        btnRegister = (Button) findViewById(;
        btnLinkToLogin = (Button) findViewById(;
        registerErrorMsg = (TextView) findViewById(;
        // Register Button Click event
        btnRegister.setOnClickListener(new View.OnClickListener() {         
            public void onClick(View view) {
                String name = inputFullName.getText().toString();
                String email = inputEmail.getText().toString();
                String password = inputPassword.getText().toString();
                UserFunctions userFunction = new UserFunctions();
                JSONObject json = userFunction.registerUser(name, email, password);
                // check for login response
                try {
                    if (json.getString(KEY_SUCCESS) != null) {
                        registerErrorMsg.setText("Registration Successful");
                        String res = json.getString(KEY_SUCCESS); 
                        if(Integer.parseInt(res) == 1){
                            // user successfully registred
                            // Store user details in SQLite Database
                            DatabaseHandler db = new DatabaseHandler(getApplicationContext());
                            JSONObject json_user = json.getJSONObject("username");
                            // Clear all previous data in database
                            db.addUser(json_user.getString(KEY_NAME), password, json_user.getString(KEY_EMAIL));                        
                            // Launch homes Screen
                            Intent homes = new Intent(getApplicationContext(), HomesActivity.class);
                            // Close all views before launching homes
                            homes.putExtra("name", name);
                            // Close Registration Screen
                            // Error in registration
                            registerErrorMsg.setText("Error occured in registration");
                } catch (JSONException e) {
        // Link to Login Screen
        btnLinkToLogin.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent i = new Intent(getApplicationContext(),
                // Close Registration View

Java Source Code List