ForgeRock SDKs

Prepare for authentication

The sample application demonstrates user authentication. It shows the authentication status, and provides login and logout functionality.

  1. Open the activity_main.xml layout file, and add a TextView for the authentication status message, a login button, and a logout button:

    Blueprint of main app UI
    • The file to edit is app/src/main/res/layout/activity_main.xml.

    • The TextView has ID textViewUserStatus.

    • The Login button has ID buttonLogin.

    • The Logout button has ID buttonLogout.

  2. Link these items to the MainActivity class:

    private TextView status;
    private Button loginButton;
    private Button logoutButton;
    protected void onCreate(Bundle savedInstanceState) {
        status = findViewById(;
        loginButton = findViewById(;
        logoutButton = findViewById(;
        // Temporary code to check that you have properly linked the buttons:
        String TAG = MainActivity.class.getName();
        loginButton.setOnClickListener(view -> Logger.debug(TAG, "Login button is pressed"));
        logoutButton.setOnClickListener(view -> Logger.debug(TAG, "Logout button is pressed"));
        // Method to add in the next step and to uncomment after you test the buttons:
  3. Add a method to update the authentication status when it changes:

    private void updateStatus() {
        runOnUiThread(() -> {
            if (FRUser.getCurrentUser() == null) {
                status.setText("User is not authenticated.");
            } else {
                status.setText("User is authenticated.");

    After adding the method, uncomment its use in the onCreate() method.

Copyright © 2010-2022 ForgeRock, all rights reserved.