---
title: Step 5. Add login and logout calls
description: In this step, you update the app with the NodeListener interface, which manages the client side of the authentication journey.
component: sdks
version: latest
page_id: sdks:sdks:tutorials/android/05_add-login-logout
canonical_url: https://docs.pingidentity.com/sdks/latest/sdks/tutorials/android/05_add-login-logout.html
llms_txt: https://docs.pingidentity.com/sdks/llms.txt
docs_for_agents: https://developer.pingidentity.com/build-with-ai/docs-for-agents.md
revdate: Wed, 17 May 2023 14:10:20 +0100
keywords: ["PingOne Advanced Identity Cloud", "PingAM", "Journeys", "Setup &amp; Configuration", "Source Code", "Tutorial", "SDK"]
section_ids:
  implement_nodelistener_and_methods: Implement NodeListener and methods
  check_point: Check point
---

# 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:

* `onSuccess()`

  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.

* `onCallbackReceived()`

  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.

* `onException()`

  Handle any errors.

## Implement `NodeListener` and methods

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

   ```java
   public class MainActivity extends AppCompatActivity implements NodeListener<FRUser> {
   ```

2. Add import statements for `org.forgerock.android.auth.NodeListener` and `org.forgerock.android.auth.Node`:

   ```java
   import org.forgerock.android.auth.NodeListener;
   import org.forgerock.android.auth.Node;
   ```

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

   ```java
   public class MainActivity extends AppCompatActivity implements NodeListener<FRUser> {

     // …​
     // …​
     // …​

     @Override
      public void onSuccess(FRUser result) {
        updateStatus();
      }

      @Override
      public void onCallbackReceived(Node node) {
        // Display appropriate UI to handle callbacks
      }

      @Override
      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:

   ```java
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       Logger.set(Logger.Level.DEBUG);
       FRAuth.start(this);
       // Add references to status view elements
       status = findViewById(R.id.textViewUserStatus);
       loginButton = findViewById(R.id.buttonLogin);
       logoutButton = findViewById(R.id.buttonLogout);
       updateStatus();

       // Attach 'FRUser.login()' to 'loginButton'
       loginButton.setOnClickListener(view → FRUser.login(getApplicationContext(), this));

       // Attach 'FRUser.getCurrentUser().logout()' to 'logoutButton'
       logoutButton.setOnClickListener(view → {
           FRUser.getCurrentUser().logout();
           updateStatus();
       });
   }
   ```

## 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:

   ```text
   [4.8.7] [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.
