ForgeRock Developer Experience

Step 5. Add login and logout calls

In this step, you update the app with the NodeListener interface, which manages the client side of the authentication journey.

The interface provides methods to handle the results of the authentication journey:


The authentication journey is complete and an FRUser object is now available for further use.

For example, you could display the user’s name in your app.


Recursively handle each step within the authentication journey, by completing and returning any callbacks received.

For example, in this quick start guide we receive NameCallback and PasswordCallback callbacks. In the next step, we create the UI to request these credentials from the user.


Handle any errors.

Implement NodeListener and methods

  1. Edit the MainActivity class so that it implements NodeListener<FRUser>:

    public class MainActivity extends AppCompatActivity implements NodeListener<FRUser> {
  2. Add import statements for and

  3. At the bottom of the MainActivity class, add the handler methods from the NodeListener interface:

    public class MainActivity extends AppCompatActivity implements NodeListener<FRUser> {
      // ...
      // ...
      // ...
       public void onSuccess(FRUser result) {
       public void onCallbackReceived(Node node) {
         // Display appropriate UI to handle callbacks
       public void onException(Exception e) {
         Logger.error(TAG, e.getMessage(), e);
  4. Attach FRUser.login() and FRUser.logout() calls to the appropriate buttons, after the updateStatus() call:

        protected void onCreate(Bundle savedInstanceState) {
            // Add references to status view elements
            status = findViewById(;
            loginButton = findViewById(;
            logoutButton = findViewById(;
            // Attach `FRUser.login()` to `loginButton`
            loginButton.setOnClickListener(view -> FRUser.login(getApplicationContext(), this));
            // Attach `FRUser.getCurrentUser().logout()` to `logoutButton`
            logoutButton.setOnClickListener(view -> {

Check point

  1. In Android Studio, select Run  Run 'app'.

    If everything is configured correctly, the app builds, and the emulator runs the application.

  2. In the Emulator, click the Log in button.

    In the Run pane, you should see the following to indicate that the journey was found and the callbacks were returned. In our case, a NameCallback and PasswordCallback callback, as configured in the page node:

    D/ForgeRock: [3.4.0] [AuthServiceResponseHandler]: Journey callback(s) received.

In the next step, you add a UI fragment to obtain credentials from the user, and code to open that fragment when the callback is received.

You also add code to populate the callback with the credentials and return it to the server, completing the authentication journey.

Copyright © 2010-2024 ForgeRock, all rights reserved.