• /
  • EnglishEspañolFrançais日本語한국어Português
  • 로그인지금 시작하기

Android agent custom interactions

중요

This feature works correctly only if Default Interactions are disabled at runtime and configured appropriately at buildtime.

Creating custom interactions

You can create custom interactions and enhance them with additional information. If custom interactions are not closed explicitly, the New Relic agent automatically closes them and sends the data to the New Relic Platform.

To create a custom interaction, use startInteraction to begin the interaction and endInteraction to close it. The system automatically measures the timing.

Java

// Start a custom interaction
String id = NewRelic.startInteraction("Tap on Search");
// ...do some work here...
// End the custom interaction
NewRelic.endInteraction(id);

Kotlin

// Start a custom interaction
val id = NewRelic.startInteraction("Tap on Search")
// ...do some work here...
// End the custom interaction
NewRelic.endInteraction(id)

These methods allow you to capture the duration and details of specific interactions within your application, providing deeper insights into user behavior and application performance.

Create child traces with custom interactions

Child traces are similar to custom interactions. When a parent custom interaction is closed, the New Relic agent automatically closes all child method traces associated with that parent custom interaction.

To generate child traces, use the NewRelic.startMethodTrace() method. Here's how you can implement parent custom interactions and child traces:

Java

// Start a parent custom interaction
String parentId = NewRelic.startInteraction("Main Activity");
// Start a child trace
NewRelic.startMethodTrace("Load Resource From Database");
// ...do some work here...
// End the child trace
NewRelic.endMethodTrace();
// Start another child trace
NewRelic.startMethodTrace("Load Resource From Server");
// ...do some work here...
// End the child trace
NewRelic.endMethodTrace();
// End the parent interaction
NewRelic.endInteraction(parentId);

Kotlin

// Start a parent custom interaction
val parentId = NewRelic.startInteraction("Main Activity")
// Start a child trace
NewRelic.startMethodTrace("Loop 1 Run")
// ...do some work here...
// End the child trace
NewRelic.endMethodTrace()
// Start another child trace
NewRelic.startMethodTrace("Loop 2 Run")
// ...do some work here...
// End the child trace
NewRelic.endMethodTrace()
// End the parent interaction
NewRelic.endInteraction(parentId)

Considerations

  • If you want to create custom interactions with method traces, you need to start and end the interaction without any user intervention.
  • If you want to calculate the time between two interactions that involve user intervention, you should not create child traces for these interactions.

This approach enables detailed tracking and measurement of interactions within your mobile application to provide valuable insights into application performance and user behavior.

Copyright © 2025 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.