com.preemptive.instrumentation
Class AndroidHelper

java.lang.Object
  extended by com.preemptive.instrumentation.AndroidHelper

public final class AndroidHelper
extends Object

Useful methods for instrumenting Android applications.

Suggested use of application start and stop

It is recommended that you place your calls to RuntimeIntelligence.startApplication() and RuntimeIntelligence.stopApplication() in your initial Activity:

 
 public class MyActivity extends Activity {
 
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         RuntimeIntelligence.setCompanyId(COMPANY_ID);
         RuntimeIntelligence.setApplicationId(APP_ID);
         // additional configuration
         RuntimeIntelligence.startApplication(this, null);
         if(savedInstanceState == null){
             RuntimeIntelligence.systemProfile();
         }
         // ...
     }
 
     protected void onDestroy() {
         // ...
         if(isFinishing()){
             RuntimeIntelligence.stopApplication();
         }
         super.onDestroy();
     }
 }
 

Using onStartActivity() and onStopActivity()

You can use the methods in this class to start and stop RuntimeIntelligence from the onStart() and onStop() methods of all of your activities:

 
 public class MyActivity extends Activity {
     protected void onCreate(Bundle savedInstanceState) {
         // The initial activity should configure but not start
         // PreEmptive Analytics in its onCreate().
         RuntimeIntelligence.setCompanyId(COMPANY_ID);
         RuntimeIntelligence.setApplicationId(APP_ID);
         // additional configuration
     }
     
     protected void onStart() {
         super.onStart();
         if((AndroidHelper.onStartActivity(this)){
             RuntimeIntelligence.systemProfile();
         }
         // ...
     }
     
     protected void onStop() {
         super.onStop();
         AndroidHelper.onStopAcivity(this);
         // ...
     }
 }
 


Constructor Summary
AndroidHelper()
           
 
Method Summary
static boolean onStartActivity(Context activityContext)
          To be called from Activity.onStart().
static boolean onStartActivity(Context activityContext, BinaryInfo binary)
          To be called from Activity.onStart().
static boolean onStartActivity(Context activityContext, BinaryInfo binary, Properties properties)
          To be called from Activity.onStart().
static boolean onStartActivity(Context activityContext, Properties properties)
          To be called from Activity.onStart().
static void onStopActivity(Context activityContext)
          To be called from Activity.onStop().
static void onStopActivity(Context activityContext, BinaryInfo binary)
          To be called from Activity.onStop().
static void onStopActivity(Context activityContext, BinaryInfo binary, Properties properties)
          To be called from Activity.onStop().
static void onStopActivity(Context activityContext, Properties properties)
          To be called from Activity.onStop().
static void setContinueTimeout(int timeout)
          Sets the timeout period between activities that indicates the session has ended.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AndroidHelper

public AndroidHelper()
Method Detail

setContinueTimeout

public static void setContinueTimeout(int timeout)
Sets the timeout period between activities that indicates the session has ended.

Parameters:
timeout - the timeout in milliseconds.
See Also:
onStartActivity(Context), onStopActivity(Context)

onStartActivity

public static boolean onStartActivity(Context activityContext)
To be called from Activity.onStart(). This can cause a RuntimeIntelligence start message to be sent if the application is not already running. If the application and company IDs have not been set the application will not be started. If opt-in has been set to false application will not be started.

Parameters:
activityContext - the activity that is starting.
See Also:
RuntimeIntelligence.startApplication(), ris.log.messages

onStartActivity

public static boolean onStartActivity(Context activityContext,
                                      BinaryInfo binary)
To be called from Activity.onStart(). This can cause a RuntimeIntelligence start message to be sent if the application is not already running. If the application and company IDs have not been set the application will not be started. If opt-in has been set to false application will not be started.

Parameters:
activityContext - the activity that is starting.
binary - optional information about the program element requesting the start
See Also:
RuntimeIntelligence.startApplication(), ris.log.messages

onStartActivity

public static boolean onStartActivity(Context activityContext,
                                      Properties properties)
To be called from Activity.onStart(). This can cause a RuntimeIntelligence start message to be sent if the application is not already running. If the application and company IDs have not been set the application will not be started. If opt-in has been set to false application will not be started.

Parameters:
activityContext - the activity that is starting.
properties - optional properties to be sent with the message
See Also:
RuntimeIntelligence.startApplication(), ris.log.messages

onStartActivity

public static boolean onStartActivity(Context activityContext,
                                      BinaryInfo binary,
                                      Properties properties)
To be called from Activity.onStart(). This can cause a RuntimeIntelligence start message to be sent if the application is not already running. If the application and company IDs have not been set the application will not be started. If opt-in has been set to false application will not be started.

Parameters:
activityContext - the activity that is starting.
binary - optional information about the program element requesting the start
properties - optional properties to be sent with the message
See Also:
RuntimeIntelligence.startApplication(), ris.log.messages

onStopActivity

public static void onStopActivity(Context activityContext)
To be called from Activity.onStop(). This can cause a stop message to be sent if the application is running.

Parameters:
activityContext - the activity that is stopping.
See Also:
RuntimeIntelligence.startApplication()

onStopActivity

public static void onStopActivity(Context activityContext,
                                  BinaryInfo binary)
To be called from Activity.onStop(). This can cause a stop message to be sent if the application is running.

Parameters:
activityContext - the activity that is stopping.
binary - optional information about the program element requesting the start
See Also:
RuntimeIntelligence.startApplication()

onStopActivity

public static void onStopActivity(Context activityContext,
                                  Properties properties)
To be called from Activity.onStop(). This can cause a stop message to be sent if the application is running.

Parameters:
activityContext - the activity that is stopping.
properties - optional properties to be sent with the message
See Also:
RuntimeIntelligence.startApplication()

onStopActivity

public static void onStopActivity(Context activityContext,
                                  BinaryInfo binary,
                                  Properties properties)
To be called from Activity.onStop(). This can cause a stop message to be sent if the application is running.

Parameters:
activityContext - the activity that is stopping.
binary - optional information about the program element requesting the start
properties - optional properties to be sent with the message
See Also:
RuntimeIntelligence.startApplication()


Copyright © 2013 PreEmptive Solutions, LLC. All Rights Reserved.