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:
- To close the active session, use the closeSession() method:
- To manually flush all saved data, use the flush() method:
- 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:
Mint.startSession(this.getApplication());
Note If a session is already open, this method does not open a new session.
Mint.closeSession();
Mint.flush();
<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(); } }
Use ProGuard with Splunk MINT | Monitor transactions |
This documentation applies to the following versions of Splunk MINT™ SDK for Android (Legacy): 5.2.x
Feedback submitted, thanks!