0

I am creating an app where it will store some data of any user, for example, could storage, where user can store files, photos etc. I have put option for sign up where user can sign up and create an account there. Now, I want to implement this, the user should get page by page input sign up pages, meaning, after clicking on sign up, an activity will open that one will be the 1st activity where user will see edit text and a next button, in edit text user will put name and press next button. after clicking next 2nd activity invoked and user can put DOB in edit text then press next, 3rd activity invoked and user can put email then next and then 4th activity user can put password and confirm password and press login and in 5th activity user will be in the homepage, just like creating an account in gmail app. I want a replica like that in my app. To store the signup details in server I have use parse platform server, and successfully implemented on my app, the code given below shows all the input details in the same page, so how can I bifurcate it into the page by page as I have mentioned above. here is the code:- user clicks on signup button

 EditText edName, edEmail, edPassword, edConfirmPassword;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);

    edName = findViewById(R.id.edName);
    edEmail = findViewById(R.id.edEmail);
    edPassword = findViewById(R.id.edPassword);
    edConfirmPassword = findViewById(R.id.edConfirmPassword);
}

public void signup(View view) { //signup button
    if( TextUtils.isEmpty(edName.getText())){
        edName.setError( "Name is required!" );
    }else if( TextUtils.isEmpty(edEmail.getText())){
        edEmail.setError( "Email is required!" );
    }else if( TextUtils.isEmpty(edPassword.getText())){
        edPassword.setError( "Password is required!" );
    }else if( TextUtils.isEmpty(edConfirmPassword.getText())){
        edConfirmPassword.setError( "Confirm password is required!" );
    }else if(!edPassword.getText().toString().equals(edConfirmPassword.getText().toString())){
        Toast.makeText(SignupActivity.this, "Passwords are not the same!", Toast.LENGTH_LONG).show();
    }else{

        final ProgressDialog progress = new ProgressDialog(this);
        progress.setMessage("Loading ...");
        progress.show();
        ParseUser user = new ParseUser();
        user.setUsername(edEmail.getText().toString().trim());
        user.setEmail(edEmail.getText().toString().trim());
        user.setPassword(edPassword.getText().toString());
        user.put("name", edName.getText().toString().trim());
        user.signUpInBackground(new SignUpCallback() {
            @Override
            public void done(ParseException e) {
                progress.dismiss();
                if (e == null) {
                    Toast.makeText(SignupActivity.this, "Welcome!", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(SignupActivity.this, HomeActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    ParseUser.logOut();
                    Toast.makeText(SignupActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        });
    }
Andrew
  • 123
  • 6
  • So what exactly you want us to help you on? You have written the code so what's going wrong? – s_o_m_m_y_e_e Jun 30 '21 at 18:28
  • It is clearly mentioned in the question, I think you didn't read it well, I want separate activity for separate input details. The above code is taking as a whole – Andrew Jun 30 '21 at 18:32
  • 1
    Adding to @HeshanSandeepa, use ViewPager2 library which is newer. Basically Its a view, that you can place inside an activity (or fragment) and inside of it you can swipe between different fragments. – Ofek Jun 30 '21 at 18:35
  • @Heshan thank you for the suggestion, but I have a doubt is how I will store the data suppose name, email etc and later on pass all the data in signup page and push into the server? Is it by using shared preferences or any other techniques? – Andrew Jun 30 '21 at 18:36
  • @Ofek thank you for view pager 2 library do we need to put in gradle build? – Andrew Jun 30 '21 at 18:38
  • @Andrew Yep, you could use shared preferences, class variables, or even a small database with a single table. – Heshan Sandeepa Jun 30 '21 at 18:40
  • I believe it doesn't need a special implementation in the .gradle file but I could be wrong. For your question about how to store it, it all comes down to how exactly do you need it to behave. In my opinion go with the class variables option unless you need to store it in a way that even if the app shuts down it will still initialize with all the values in the next app launch (if so, you can use shared preferences) – Ofek Jun 30 '21 at 18:45
  • @HeshanSandeepa by using shared preferences or class variables I collected the values that is input by user and then after that can I push the data into the parse server? If yes then how to and where to write the code any link or tutorial or hint? because right now I am really block... – Andrew Jun 30 '21 at 18:48
  • @Ofek can you give me some hint, or any tutorial please... – Andrew Jun 30 '21 at 18:50
  • @Andrew there is no way to get stuck. Kindly note that StackOverflow won't write any code for you. Please Google Android view pages & parse-platform. You may start from here, http://docs.parseplatform.org/android/guide/ – Heshan Sandeepa Jun 30 '21 at 18:57
  • By coincidence I did something similar not a long time ago, I'll try to share to basic idea in a bit. – Ofek Jun 30 '21 at 19:04
  • @Ofek thank you. I will try to implement in my code as per your suggestion – Andrew Jun 30 '21 at 19:11
  • @HeshanSandeepa I know stack overflow won't write code for me, I just need more hint or code snippet so that I can accomplished my task. thanks for the doc link I have already read it and that's why I made the app just need extra functionalities, that's why I need help. anyways thank you for your help. – Andrew Jun 30 '21 at 19:14
  • Hey @Andrew, Please view this https://stackoverflow.com/questions/54643379/proper-implementation-of-viewpager2-in-android It explains how to implement viewpager2 in your app. for you case I see you have a ParseUser class, you can store it in a variable and then every step through the ViewPager you can incrementally set each field and then send the object to the server. Furthermore, you might want to save the fields in SharedPreferences, for that simply google android shared preferences example and I'm sure you'll find a lot of good content. Goodluck :) – Ofek Jun 30 '21 at 19:37

2 Answers2

2

As @Zahid mentioned the code I just modified a little bit so that your confusion will be clear. Yes you can use Shared Preferences instead of any library or viewpager. As you mentioned above @Andrew that you want to show your activity step by step and take data from each activity and at last activity, user can sign up. For that you have to create an activity, say User_name.java, and the code will be:- on create:

eName = findViewById(R.id.eName);
nextbtn = findViewById(R.id.nextbtn);
String name;


    nextbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            name = eName.getText().toString();
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putString("Usrname", name);
            editor.apply();
            Toast.makeText(User_Name.this, "Name saved", Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(User_Name.this, Sign_Up.class);
            startActivity(intent);
        }
    });

For User_Name.java create this as an empty activity and put EditText and a Button in xml file, then, I modified your above mentioned code and gave name as Sign_Up.java, since you didn't mentioned the file name, here is the code:-

EditText edEmail,edPassword, edConfirmPassword; //edName, 
TextView t1, t2;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);

    t1 = findViewById(R.id.Textname);
    SharedPreferences tx = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String name = tx.getString("Usrname"," ");
    t1.setText(name);

   

   // edName = findViewById(R.id.edName);
    edEmail = findViewById(R.id.edEmail);
    edPassword = findViewById(R.id.edPassword);
    edConfirmPassword = findViewById(R.id.edConfirmPassword);
}

public void signup(View view) {
   /* if( TextUtils.isEmpty(edName.getText())){
        edName.setError( "Name is required!" );
    }else */ if( TextUtils.isEmpty(edEmail.getText())){
        edEmail.setError( "Email is required!" );
    }else if( TextUtils.isEmpty(edPassword.getText())){
        edPassword.setError( "Password is required!" );
    }else if( TextUtils.isEmpty(edConfirmPassword.getText())){
        edConfirmPassword.setError( "Confirm password is required!" );
    }else if(!edPassword.getText().toString().equals(edConfirmPassword.getText().toString())){
        Toast.makeText(SignupActivity.this, "Passwords are not the same!", Toast.LENGTH_LONG).show();
    }else{

        final ProgressDialog progress = new ProgressDialog(this);
        progress.setMessage("Loading ...");
        progress.show();
        ParseUser user = new ParseUser();
        user.setUsername(edEmail.getText().toString().trim());
        user.setEmail(edEmail.getText().toString().trim());
        user.setPassword(edPassword.getText().toString());
        user.put("name", t1.getText().toString().trim());
        user.signUpInBackground(new SignUpCallback() {
            @Override
            public void done(ParseException e) {
                progress.dismiss();
                if (e == null) {
                    Toast.makeText(SignupActivity.this, "Welcome!", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(SignupActivity.this, HomeActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    ParseUser.logOut();
                    Toast.makeText(SignupActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}

}

Follow this process and create separate activities like email, DOB etc and call them all in Sign_Up.java as I called for user_name.

Dharman
  • 26,923
  • 21
  • 73
  • 125
Mediad
  • 258
  • 1
  • 7
0

I think you can do that through Shared Preference. In every activity you should check if input value not equal to null then you store data and launch next activity through intent by button onclicklistener. For password comparison use logic . Finally in last activity retrieve data from Shared Preference and trigger login .

Save Data example for Name-

if (edName != null) {
                    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                    SharedPreferences.Editor editor = pref.edit();
                    editor.putString("name", edName);
                    editor.commit();

Retrive Data example -

  public String edName;
SharedPreferences defPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    edName  = defPref.getString("name","");
Zahid Islam
  • 705
  • 1
  • 5
  • 11
  • Thanks but do I need to use viewpager or any other library? or we can accomplish by creating activities for each edit text with buttons? then save details in shared preferences and later on at the last activity we retrieve the data and push into the server. is it? – Andrew Jun 30 '21 at 18:56
  • No others library , just activities with edit text and button . Save and then retrieve before push. – Zahid Islam Jun 30 '21 at 19:01
  • thank you, I will try to implement your suggestion – Andrew Jun 30 '21 at 19:15