public class

Foreground

extends Object
implements Application.ActivityLifecycleCallbacks
java.lang.Object
   ↳ com.steerpath.sdk.utils.Foreground

Class Overview

Usage: 1. Get the Foreground Singleton, passing a Context or Application object unless you are sure that the Singleton has definitely already been initialised elsewhere. 2.a) Perform a direct, synchronous check: Foreground.isForeground() / .isBackground() or 2.b) Register to be notified (useful in Service or other non-UI components): Foreground.Listener myListener = new Foreground.Listener(){ public void onBecameForeground(){ // ... whatever you want to do } public void onBecameBackground(){ // ... whatever you want to do } } public void onCreate(){ super.onCreate(); Foreground.get(this).addListener(listener); } public void onDestroy(){ super.onCreate(); Foreground.get(this).removeListener(listener); }

Summary

Nested Classes
interface Foreground.Listener  
Constants
long CHECK_DELAY
Fields
public static final String TAG
Public Constructors
Foreground()
Public Methods
void addListener(Foreground.Listener listener)
static Foreground get()
static Foreground get(Application application)
static Foreground get(Context ctx)
static Foreground init(Application application)
Its not strictly necessary to use this method - _usually_ invoking get with a Context gives us a path to retrieve the Application and initialise, but sometimes (e.g.
boolean isBackground()
boolean isForeground()
void onActivityCreated(Activity activity, Bundle savedInstanceState)
void onActivityDestroyed(Activity activity)
void onActivityPaused(Activity activity)
void onActivityResumed(Activity activity)
void onActivitySaveInstanceState(Activity activity, Bundle outState)
void onActivityStarted(Activity activity)
void onActivityStopped(Activity activity)
void removeListener(Foreground.Listener listener)
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.app.Application.ActivityLifecycleCallbacks

Constants

public static final long CHECK_DELAY

Constant Value: 500 (0x00000000000001f4)

Fields

public static final String TAG

Public Constructors

public Foreground ()

Public Methods

public void addListener (Foreground.Listener listener)

public static Foreground get ()

public static Foreground get (Application application)

public static Foreground get (Context ctx)

public static Foreground init (Application application)

Its not strictly necessary to use this method - _usually_ invoking get with a Context gives us a path to retrieve the Application and initialise, but sometimes (e.g. in test harness) the ApplicationContext is != the Application, and the docs make no guarantees.

Returns
  • an initialised Foreground instance

public boolean isBackground ()

public boolean isForeground ()

public void onActivityCreated (Activity activity, Bundle savedInstanceState)

public void onActivityDestroyed (Activity activity)

public void onActivityPaused (Activity activity)

public void onActivityResumed (Activity activity)

public void onActivitySaveInstanceState (Activity activity, Bundle outState)

public void onActivityStarted (Activity activity)

public void onActivityStopped (Activity activity)

public void removeListener (Foreground.Listener listener)