Package com.batch.android.runtime
Class RuntimeManager
- java.lang.Object
-
- com.batch.android.runtime.RuntimeManager
-
public class RuntimeManager extends java.lang.ObjectManager that contains library state and locks
-
-
Constructor Summary
Constructors Constructor Description RuntimeManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanchangeState(ChangeStateAction action)Execute an action to modify the statebooleanchangeStateIf(State wantedState, ChangeStateAction action)Execute an action to modify the state if the current state equals the wanted onevoidclearSessionManager()voiddecrementServiceRefCount()Decrement the number of services retaining Batch.android.app.ActivitygetActivity()Get the activityandroid.content.ContextgetContext()Get the contextjava.util.DategetLastUserStartDate()Get the last time Batch was started for user activity.java.lang.StringgetSessionIdentifier()SessionManagergetSessionManager()voidincrementServiceRefCount()Increment the number of calls to onServiceCreate registeredbooleanisApplicationInForeground()booleanisReady()Checks if Batch is readybooleanisRetainedByService()Checks if the service's refcount is greater than 0java.lang.LongonStart()Method to call when onStart is called to get the last stop timestamp (if any)
This method is NOT thread safe, should only be called on a changeState methodvoidonStopWithoutFinishing()Method to call when onStop is called without a finishing activity This method is NOT thread safe, should only be called on a changeState methodvoidregisterActivityListenerIfNeeded(android.app.Application application)voidregisterSessionManagerIfNeeded(android.app.Application application, boolean simulateActivityStart)voidresetServiceRefCount()Forces the service ref count to be zero Dangerousvoidrun(StateAction action)Execute an action with read lockbooleanrunIf(State wantedState, StateAction action)Execute an action with read lock if the current state equals the wanted statebooleanrunIf(State wantedState, java.lang.Runnable action)Run this action if Batch is at the given wanted statebooleanrunIfReady(java.lang.Runnable action)Run this action if Batch is readyvoidsetActivity(android.app.Activity activity)Set the activity, you should NEVER call this method outside of a changeState method
This method is NOT thread safevoidsetContext(android.content.Context context)Set the context, you should NEVER call this method outside of a changeState method
This method is NOT thread safevoidupdateLastUserStartDate()Set the last time the Batch was started for user activity to now.
-
-
-
Method Detail
-
changeState
public boolean changeState(ChangeStateAction action)
Execute an action to modify the state- Parameters:
action- action that will modify the given state- Returns:
- true if the state has been set, false otherwise
-
changeStateIf
public boolean changeStateIf(State wantedState, ChangeStateAction action)
Execute an action to modify the state if the current state equals the wanted one- Parameters:
wantedState-action-- Returns:
- true if the state has been set, false otherwise
-
run
public void run(StateAction action)
Execute an action with read lock- Parameters:
action- action that can read the given state
-
runIf
public boolean runIf(State wantedState, StateAction action)
Execute an action with read lock if the current state equals the wanted state- Parameters:
wantedState-action-- Returns:
- true if the action has been run, false otherwise
-
runIfReady
public boolean runIfReady(java.lang.Runnable action)
Run this action if Batch is ready- Parameters:
action-- Returns:
- true if the action has been runned, false otherwise
-
runIf
public boolean runIf(State wantedState, java.lang.Runnable action)
Run this action if Batch is at the given wanted state- Parameters:
wantedState-action-- Returns:
- true if the action has been runned, false otherwise
-
onStart
public java.lang.Long onStart()
Method to call when onStart is called to get the last stop timestamp (if any)
This method is NOT thread safe, should only be called on a changeState method- Returns:
- the timestamp of the last stop if any, null otherwise. If null, you should always restart
-
onStopWithoutFinishing
public void onStopWithoutFinishing()
Method to call when onStop is called without a finishing activity This method is NOT thread safe, should only be called on a changeState method
-
setActivity
public void setActivity(android.app.Activity activity)
Set the activity, you should NEVER call this method outside of a changeState method
This method is NOT thread safe- Parameters:
activity-
-
getActivity
public android.app.Activity getActivity()
Get the activity- Returns:
- activity or null depending on the state
-
incrementServiceRefCount
public void incrementServiceRefCount()
Increment the number of calls to onServiceCreate registered
-
decrementServiceRefCount
public void decrementServiceRefCount()
Decrement the number of services retaining Batch.
-
resetServiceRefCount
public void resetServiceRefCount()
Forces the service ref count to be zero Dangerous
-
isReady
public boolean isReady()
Checks if Batch is ready
-
isRetainedByService
public boolean isRetainedByService()
Checks if the service's refcount is greater than 0
-
updateLastUserStartDate
public void updateLastUserStartDate()
Set the last time the Batch was started for user activity to now. You should NEVER call this method outside of a changeState method
This method is NOT thread safe
-
getLastUserStartDate
public java.util.Date getLastUserStartDate()
Get the last time Batch was started for user activity.- Returns:
- last user activity start date or null depending on the state
-
setContext
public void setContext(android.content.Context context)
Set the context, you should NEVER call this method outside of a changeState method
This method is NOT thread safe- Parameters:
context-
-
getContext
public android.content.Context getContext()
Get the context- Returns:
- context or null
-
registerActivityListenerIfNeeded
public void registerActivityListenerIfNeeded(@NonNull android.app.Application application)
-
isApplicationInForeground
public boolean isApplicationInForeground()
-
registerSessionManagerIfNeeded
public void registerSessionManagerIfNeeded(@NonNull android.app.Application application, boolean simulateActivityStart)
-
getSessionIdentifier
public java.lang.String getSessionIdentifier()
-
getSessionManager
public SessionManager getSessionManager()
-
clearSessionManager
public void clearSessionManager()
-
-