cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mobile app manual instrumentation with multiple frameworks

gilgi
Advisor

Hi everyone,

We have a customer who is developing a financial payment application that is using a framework of HCE. Unfortunately, Java does not support extending the basic App class based on multiple classes and we need to provide a way to use the agent.

Has anyone faced a similar problem ?

1 REPLY 1

Thomas_Wirth1
Dynatrace Pro
Dynatrace Pro

Hi Gil,

I assume you are talking about the lifecycle instrumentation, where you have to inherit your activity classes from the Dynatrace activity classes. In this case you have two options:

You could use auto-instrumentation to automatically instrument all activities. This will also work for third party activities.

For manual instrumentation (with a 6.3 agent) you have to generate a wrapper class for this third party activities. You have to execute the following steps:

  1. Generate a class with the name of activity class in the package `com.dynatrace.android.app`.
  2. Copy the code snippet below into your new class file.
  3. Replace the activity name placeholder with the activity name.
  4. Derive your activity classes from the new wrapper class.
package com.dynatrace.android.app;

import android.os.Bundle;

public abstract class <activity_name> extends <package_name>.<activity_name> {

@Override
protected void onCreate(Bundle savedInstanceState) {
if (LcContext.getInstance().isLifecycleInEffect()) {
LcContext.getInstance().getActivityLcCallbacks().onActivityCreate(this, savedInstanceState);
}

super.onCreate(savedInstanceState);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
if (LcContext.getInstance().isLifecycleInEffect()) {
LcContext.getInstance().getActivityLcCallbacks().onActivityPostCreate(this, savedInstanceState);
}

super.onPostCreate(savedInstanceState);
}

@Override
protected void onRestart() {
if (LcContext.getInstance().isLifecycleInEffect()) {
LcContext.getInstance().getActivityLcCallbacks().onActivityRestart(this);
}

super.onRestart();
}

@Override
protected void onStart() {
if (LcContext.getInstance().isLifecycleInEffect()) {
LcContext.getInstance().getActivityLcCallbacks().onActivityStart(this);
}

super.onStart();
}

@Override
protected void onResume() {
if (LcContext.getInstance().isLifecycleInEffect()) {
LcContext.getInstance().getActivityLcCallbacks().onActivityResume(this);
}

super.onResume();
}

@Override
protected void onPostResume() {
if (LcContext.getInstance().isLifecycleInEffect()) {
LcContext.getInstance().getActivityLcCallbacks().onActivityPostResume(this);
}

super.onPostResume();
}

@Override
protected void onPause() {
if (LcContext.getInstance().isLifecycleInEffect()) {
LcContext.getInstance().getActivityLcCallbacks().onActivityPause(this);
}

super.onPause();
}

@Override
protected void onStop() {
if (LcContext.getInstance().isLifecycleInEffect()) {
LcContext.getInstance().getActivityLcCallbacks().onActivityStop(this);
}

super.onStop();
}

@Override
protected void onDestroy() {
if (LcContext.getInstance().isLifecycleInEffect()) {
LcContext.getInstance().getActivityLcCallbacks().onActivityDestroy(this);
}

super.onDestroy();
}

}

Example: If your activity classes inherit from the AppCompatActivity class, then you have to generate the following wrapper class.

public abstract class AppCompatActivity extends android.support.v7.app.AppCompatActivity {