Sample pre-BlackBerry 10 app

LoclayticsSkeletonApp.java
package com.Localytics.SkeletonApp;import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;// Import the localytics Library
import com.Localytics.LocalyticsSession.*;/**
* A very simple application used to demonstrate a Localytics integration. In this
* case the application is only tracking two things:
* 1) Session open and close
* 2) What method the user used to exit the application.
*/
public class LocalyticsSkeletonApp extends UiApplication
{
public static void main(String[] args)
{
LocalyticsSkeletonApp theApp = new LocalyticsSkeletonApp();
theApp.enterEventDispatcher();
}LocalyticsSkeletonApp()
{
// open the session and begin uploading.
_session.open();
_session.upload();
pushScreen(new LocalyticsSkeletonAppScreen());
}
 
// All exit points for the application come here. This is not required, but
// it is a good practice because it keeps from having to add exit-time code
// (such as closing the Localytics session) to every exit path.
public void exit()
{
this._session.close();
System.exit(0);
}
 
// Exposes the LocalyticsSession to all future screens. This is not necessary
// for this sample. Instead, this object could be created in the MainScreen
// and referred to from there. However, it is a good practice to make the
// object globally accessible so that if screens are added in the future it is
// easy to tagEvents, or even close the session from those screens.
public LocalyticsSession getLocalyticsSession()
{
return this._session;
}
 
// Create the Localytics Object.
private final static String APPLICATION_KEY = "application_key_from_webservice";
private LocalyticsSession _session = new LocalyticsSession(APPLICATION_KEY);
}
 
final class LocalyticsSkeletonAppScreen extends MainScreen
{
// For this application, track the two ways users can exit. This is done
// by writing one of these events when a user exits.
private final static String EVENT_BTN_EXIT = "EXIT_FROM_BUTTON";
private final static String EVENT_CLOSE_APP = "EXIT_BY_CLOSING";
 
public LocalyticsSkeletonAppScreen()
{
setTitle("Localytics Skeleton App");
 
// Add an exit button to the application to demonstrate a second exit point.
ButtonField exitButton = new ButtonField("Exit");
exitButton.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
// Fire the Button exit event
((LocalyticsSkeletonApp)UiApplication.getUiApplication()).
getLocalyticsSession().tagEvent(LocalyticsSkeletonAppScreen.EVENT_BTN_EXIT);
 
// Call the global exit. This isn't necessary, but if it isn't done
// LocalyticsSession.close() must be invoked here.
setDirty(false);
((LocalyticsSkeletonApp)UiApplication.getUiApplication()).exit();
}
});
add(exitButton);
}
 
// The other exit point for this application.
public boolean onClose()
{
// Fire the 'exit by closing' event
((LocalyticsSkeletonApp)UiApplication.getUiApplication()).
getLocalyticsSession().tagEvent(LocalyticsSkeletonAppScreen.EVENT_CLOSE_APP);
 
// Call the global exit. This isn't necessary, but if it isn't done
// LocalyticsSession.close() must be invoked here.
setDirty(false);
((LocalyticsSkeletonApp)UiApplication.getUiApplication()).exit();
return true;
}
}