'how to make automatic login to 2 different activity pages using splashscreen based on android studio user status

I have a previous automatic login application when successful login will go to the Dashboard page. I want to ask how to make auto login with 2 different activity pages based on user status, The problem that occurs in my application is that when the login session only saves SessionManager data with Status "1" , even though User Login with Status "ptt"

here is my code SplashScreen.java

sessionManager = new SessionManager(this);
        sessionManager.checkLogin2();
        sessionManager2 = new SessionManager2(this);
        sessionManager2.checkLogin3();


        if(!sessionManager.checkLogin2()){
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(welcome_activity.this, DashboardActivity.class);
                    startActivity(intent);
                    finish();
                    return;
                }
            }, 2000);
        }  else if(!sessionManager2.checkLogin3()){
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(welcome_activity.this, DashboardActivityP.class);
                    startActivity(intent);
                    finish();
                    return;
                }
            }, 2000);
        }
        else {
            Intent intent = new Intent(welcome_activity.this, LoginActivity.class);
            startActivity(intent);
            finish();
        }
    }

SessionManager.java

public boolean isLoggin(){
        return sharedPreferences.getBoolean(LOGIN, false);
    }
    public boolean checkLogin2(){
        return !this.isLoggin();
    }
    public void checkLogin(){


        if (!this.isLoggin()){
            Intent i = new Intent(context, welcome_activity.class);
            context.startActivity(i);
            ((DashboardActivity) context).finish();
        }
        if (!this.isLoggin()){
            Intent i = new Intent(context, LoginActivity.class);
            context.startActivity(i);

SessionManager2.java

 public boolean isLoggin(){
            return sharedPreferences.getBoolean(LOGIN, false);
        }
        public boolean checkLogin3(){
            return !this.isLoggin();
        }
        public void checkLogin(){
    
            if (!this.isLoggin()){
                Intent i = new Intent(context, welcome_activity.class);
                context.startActivity(i);
                ((DashboardActivityP) context).finish();
            }

I conclude if the status is "1" then the page is redirected to DasboardActivity, if the login status is "ptt" then it is redirected to the DashboarActivityP page login.java

 private void requestLogin() {
                    mApiService.login(txtusername.getText().toString(), txtpassword.getText().toString())
                            .enqueue(new Callback<ResponseBody>() {
                                @Override
                                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                                    if (response.isSuccessful()) {
                                        loading.dismiss();
                                        try {
                                            JSONObject jsonRESULTS = new JSONObject(response.body().string());
                                            JSONArray jsonArray = jsonRESULTS.getJSONArray("result");
                                            if (jsonRESULTS.getString("value").equals("1"))
                                                for (int i = 0; i < jsonArray.length(); i++) {
                                                    JSONObject object = jsonArray.getJSONObject(i);
                                                    String nm_lengkap = object.getString("nm_lengkap").trim();
                                                    String nip = object.getString("nip").trim();
                                                    String password = object.getString("password").trim();
                                                    String jabatan = object.getString("jabatan").trim();
                                                    String opd = object.getString("opd").trim();
                                                    String gambar = object.getString("gambar").trim();
                                                    sessionManager.createSession(nm_lengkap, nip, password, jabatan, opd,gambar);
                                                    Toast.makeText(mContext, "Berhasil Login", Toast.LENGTH_SHORT).show();
                                                    Intent intent = new Intent(LoginActivity.this, DashboardActivity.class);
    
                                                    intent.putExtra("nm_lengkap", nm_lengkap);
                                                    intent.putExtra("nip", nip);
                                                    intent.putExtra("password", password);
                                                    intent.putExtra("jabatan", jabatan);
                                                    intent.putExtra("opd", opd);
                                                    intent.putExtra("gambar", gambar);
                                                    startActivity(intent);
                                                    finish();
                                                } else if (jsonRESULTS.getString("value").equals("ptt"))
                                                for (int i = 0; i < jsonArray.length(); i++) {
                                                    JSONObject object = jsonArray.getJSONObject(i);
                                                    String nm_lengkap = object.getString("nm_lengkap").trim();
                                                    String nip = object.getString("nip").trim();
                                                    String password = object.getString("password").trim();
                                                    String jabatan = object.getString("jabatan").trim();
                                                    String opd = object.getString("opd").trim();
                                                    String gambar = object.getString("gambar").trim();
                                                    sessionManager2.createSession(nm_lengkap, nip, password, jabatan, opd,gambar);
                                                    Toast.makeText(mContext, "Berhasil Login", Toast.LENGTH_SHORT).show();
                                                    Intent intent = new Intent(LoginActivity.this, DashboardActivityP.class);
    
                                                    intent.putExtra("nm_lengkap", nm_lengkap);
                                                    intent.putExtra("nip", nip);
                                                    intent.putExtra("password", password);
                                                    intent.putExtra("jabatan", jabatan);
                                                    intent.putExtra("opd", opd);
                                                    intent.putExtra("gambar", gambar);
                                                    startActivity(intent);
                                                    finish();
                                                }


   


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source