Android if the user is not logged in, skip to the login page where should this logic be implemented in activity?

android if the user is not logged in, skip to the login page where should this logic be implemented in activity?

Feb.28,2021

there are two ways to deal with it:

  1. @ ShawnXiaFei
  2. write to BaseActivity
public class BaseActivity extends AppCompatActivity {
    public boolean acquireAuthorization() {
        if (!isAuthorized()) {
            if (!onAcquireAuthorization()) {
                finish();            
                return false;
            }
        }
        return true;
    }
    
    public boolean isAuthorized() {
        return true;
    }

    public boolean onAcquireAuthorization() {
        return false;
    }
}
public class AppActivity extends BaseActivity {
    @Override
    public boolean isAuthorized() {
        // TODO
        return super.isAuthorized();
    }

    @Override
    public boolean onAcquireAuthorization() {
        // TODO
        return super.onAcquireAuthorization();
    }
}
public class MainActivity extends AppActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (acquireAuthorization()) {
            // TODO ...
        }
    }
}

1, add the startup page, make a judgment on the startup page, log in to the home page, and jump to the login page if you don't log in.
2. When judging the onCreate of the home page, jump directly to the login page without logging in, and finish the home page at the same time.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-4b6e654-1e588.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-4b6e654-1e588.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?