Session Reporting
Now that you've added the Embrace SDK to your project and can login to the Embrace dashboard, you're ready to create your first session.
Here are the steps you'll be taking to create your first session.
- Import Embrace
- Add a start call to the Embrace SDK
- End the startup moment
- Build and run the application
- Trigger a session upload
Import Embrace
First, import Embrace in your Application
subclass.
- Kotlin
- Java
import io.embrace.android.embracesdk.Embrace
import io.embrace.android.embracesdk.Embrace;
Add the Start Call
Next, initialize the Embrace SDK in the onCreate
method of your Application
subclass.
- Kotlin
- Java
class MyApplication : Application {
override fun onCreate() {
super.onCreate()
Embrace.getInstance().start(this)
}
}
public final class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Embrace.getInstance().start(this);
}
}
We currently recommend that you start the SDK on the main thread to ensure you're capturing mobile telemetry and crashes as soon as possible.
End the startup moment
The Embrace SDK automatically records a special "startup" moment that's used to track app launch performance.
The end of the startup moment is recorded when the Activity.onResume()
method returns.
However, if onResume()
is not a good indication of when the app launch has ended (apps that have a splash screen, for example),
you can use the @StartupActivity
annotation to indicate that you don't want the startup moment to end when the onResume
method returns.
Add the @StartupActivity
annotation to any Activity class where this applies.
- Kotlin
- Java
@StartupActivity
class MainActivity : Activity
@StartupActivity
public class MainActivity extends Activity {
}
Then, end the startup moment manually by making the following method call.
- Kotlin
- Java
Embrace.getInstance().endAppStartup()
Embrace.getInstance().endAppStartup();
You should end the startup moment before the user has a chance to interact with the application. Add this method call to every location where the startup moment can end. You can call this method as many times as you like.
{
"app_id": "xxxxx",
"api_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
Build and Run the Application
Now you're ready to build and run the application. Assuming the app launches correctly, pay attention to the system logging and confirm Embrace prints its version number.
Embrace SDK started. API key: xxxxx Version: 6.14.0
If you encounter any errors, please get in touch on Slack and we can assist you.
Trigger a Session Upload
You can trigger a session upload by sending your app to the background, and restarting it again. Refresh the dashboard in your browser and you should now see that you've moved on to the next step.
If you stop your application by either force killing it or using the Android Studio stop button, the Embrace SDK will not be able to upload the session that was just completed until you restart your application. During the next application launch the previous session will be immediately uploaded.
Congratulations! At this point you've completed a basic integration of Embrace. Embrace is already collecting interesting data from your application. You can see this data by browsing around the timeline page for the session you just captured.
Up next, you'll be learning about uploading crash reports.