Splunk MINT SDK for Android

Splunk MINT SDK for Android Developer Guide

Download manual as PDF

Download topic as PDF

Customize session handling

By default, Splunk MINT uses the initAndStartSession or initAndStartSessionHEC method and the time zone of our servers to calculate the time a user's session begins. Splunk MINT also flushes data automatically. However, you might want to customize session handling.

Use the following methods to start, close, and flush sessions:

  • To explicitly start the session, use the startSession(context) method at the onStart method of your activity:
  • Mint.startSession(this.getApplication());
    

    Note If a session is already open, this method does not open a new session.

  • To close the active session, use the closeSession() method:
  • Mint.closeSession();
    
  • To manually flush all saved data, use the flush() method:
  • Mint.flush();
    
  • To only send data over a WiFi connection, use the setFlushOnlyOverWiFi(true) method and verify you have added the following line to your app's AndroidManifest.xml file:
  • <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    

Example code

public MyActivity extends Activity {

    // Initialize and start the session
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // TODO: Update with your API key
        Mint.initAndStartSession(this.getApplication(), "YOUR_API_KEY");

        // Your code here
    }

    // Resume the session
    public void onResume() {
        super.onResume();
        Mint.startSession(this.getApplication());
    }

    // Stop the session
    public void onStop() {
        super.onStop();
        Mint.closeSession();
    }
}


Example code: Custom exit method

Let's say you have implemented your own exit method using a button in your AndroidManifest.xml layout file or using a dialog box that intercepts the onback key event. The modified code below explicitly defines an exit method as the indicator that a session has ended. In this case, the user explicitly exited the application.

public MyActivity extends Activity {

    // Initialize and start the session
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // TODO: Update with your API key
        Mint.initAndStartSession(this.getApplication(), "YOUR_API_KEY");

        // Your code here
    }

    // Resume the session
    public void onResume() {
        super.onResume();
        Mint.startSession(this.getApplication());
    }

    // Confirm the dialog box
    public void userSelectedToExit() {
        Mint.closeSession();
        this.getApplication().finish();
    }

    // Bind the xml view onClick attribute
    public void exitKeyClickAction(View view) {
        Mint.closeSession();
        this.getApplication().finish();
    }
}


Example code: Flush data

Flush session data as follows:

public MyActivity extends Activity {

    // Initialize and start the session
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // TODO: Update with your API key
        Mint.initAndStartSession(this.getApplication(), "YOUR_API_KEY");

        // Your code here
    }

    // Resume the session
    public void onResume() {
        super.onResume();
        Mint.startSession(this.getApplication());
    }

    // Stop the session
    public void onStop() {
        super.onStop();
        Mint.closeSession();
        Mint.flush();
    }
}
PREVIOUS
Use ProGuard with Splunk MINT
  NEXT
Monitor transactions

This documentation applies to the following versions of Splunk MINT SDK for Android: 5.2.x


Was this documentation topic helpful?

Enter your email address, and someone from the documentation team will respond to you:

Please provide your comments here. Ask a question or make a suggestion.

You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters