A
A
Andrey Goroshko2018-08-14 11:36:47
Android
Andrey Goroshko, 2018-08-14 11:36:47

How to save the user on the device after a successful login to the application?

I have a simple registration form in the android application, but the problem is that every time I have to enter my login and password in order to use all the functions, so I decided to somehow save the user on the device. I save the sharedpreferences refresh_token and then I try to check at the start of the application whether there is already a saved token, if there is, then we move on through the application, and if not, then we log in, here is my code:

if (!(refresh_pref == null)) {
            Intent intent = new Intent(LoginActivity.this, SecondScreen.class);
            startActivity(intent);
        } else {
            try {
                submitBtn = findViewById(R.id.btn_submit);
                submitBtn.setBackground(getDrawable(R.drawable.button));
                submitBtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        sendPost();
                    }
                });

            } catch (Exception e) {
                Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                    @Override
                    public void uncaughtException(Thread thread, Throwable ex) {
                        SendLogcatMail(thread, ex);
                    }
                });


            }
        }

maybe someone can advise how to improve this way of saving the user on the device. Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alterEgoChaos, 2018-08-14
@Drew20

how clumsily the logic is made. it’s better to make a separate splash activity in which you check if the user is authorized (is there something in preferences) and if so, open the main activity, and if not, then activate for authorization

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question