Implementing parse in my Code

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Nov 18, 2015 5:05:36 AM via Website

**I need help saving users login when they sign up on my app. What code Do I still need to make it work, so it can update to the list in the next activity how can I implement this with the code I have here:

This is my first Activity, which my app opens up to**

package com.example.yogi.taskmanager;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.parse.FindCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import java.util.List;

public class LoginActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    // Enable Local Datastore.
    Parse.enableLocalDatastore(this);
    // Enable Local Datastore.
    Parse.initialize(this, "pplnziL6pS1Hhn5utB9QunPXppj2qhd5UOUHHyuj", "qgtBDJjECnGVLsxpsBCL1NJ2Xs8ImQB1JjBvPhKn");
}


public void signUp(View view) {
    final ParseObject post = new ParseObject("Messages");
    Intent startNewActivity = new Intent(this, TaskManager.class);
    startActivity(startNewActivity);
    //also this//
}

 public void signIn(View view) {

    // Check if the entered username exists in Parse.  Proceed with logging in. If not, display a toast
    // indicating that the user does not exist
    String username = ((EditText) findViewById(R.id.editTextUsername)).getText().toString();
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Users");
    query.whereEqualTo("username", username);
    query.findInBackground(new FindCallback<ParseObject>(){
        @Override

        public void done(List<ParseObject> userList, ParseException e) {
            if (e == null) {
                // Ensure that one user was found and add it to the list of coworkers
                // for this employee
                if (userList.size() == 1) {
                    Toast toast = Toast.makeText(LoginActivity.this, "One user found.", Toast.LENGTH_LONG);
                    toast.show();
                    // Check that the password that was entered is correct.
                    // If the password is correct, then start the new Activity
                }
                else if (userList.size() == 0) {
                    Toast toast = Toast.makeText(LoginActivity.this, "User not found. They must first create their own account.", Toast.LENGTH_LONG);
                    toast.show();
                }
                // If there was more than one user, some unusual happened.  Display
                // log message and Toast.  THIS SHOULD NOT OCCUR.
                else {
                    Toast toast = Toast.makeText(LoginActivity.this, "Too Many Users Found.  ERROR", Toast.LENGTH_LONG);
                    toast.show();
                    Log.d("User", "Should be 1 or zero user. User: " + userList.get(0).getString("username"));
                }
            } else {
                Log.d("score", "Error: " + e.getMessage());
            }
        }
    });


    Intent startNewActivity = new Intent(this, MainPage.class);
    //specifies what activity it will be sent to
    //EditText theEditText = (EditText) findViewById(R.id.edit_message);
    //String message = theEditText.get;
    startActivity(startNewActivity);
    //also this//
}

}

Then I want to connect it to this activity once user is added to be updated to the list of employee names

package com.example.yogi.taskmanager;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import com.parse.ParseObject;
import com.parse.PushService;
import com.parse.Parse;

public class DisplayEmployeeActivity extends AppCompatActivity {
public final static String MESSAGE_KEY ="com.example.yogi.taskmanager.message_key";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent startNewActivity= getIntent();
//int message=startNewActivity.getIntExtra("MESSAGE_KEY", 0);
String message = startNewActivity.getStringExtra("MESSAGE_KEY");
//TextView textView = new TextView(this);
//textView.setTextSize(45);
//textView.setText(message);
//setContentView(textView);
setContentView(R.layout.activity_display_employee);
TextView textPersonName = (TextView)findViewById(R.id.editText1);
textPersonName.setText(""+ message);

    //PushService.setDefaultPushCallBack(this,TaskManager.class);

}

public void createNewTask(View view) {
    Intent startNewActivity = new Intent(this, CreateTask.class);
    //specifies what activity it will be sent to
    //EditText theEditText = (EditText) findViewById(R.id.edit_message);
    //String message = theEditText.get;
    startActivity(startNewActivity);
    //also this
}

public void mainPage(View view) {
    Intent startNewActivity = new Intent(this, MainPage.class);
    //specifies what activity it will be sent to
    //EditText theEditText = (EditText) findViewById(R.id.edit_message);
    //String message = theEditText.get;
    startActivity(startNewActivity);
    //also this

}

}