SCMHelper¶
-
public class
SCMHelper
¶ The
SCMHelper
class manages several software components throughout the application activities lifecycle.This class should be used to enable NFC reader on activity resume or to save cache on activity pause for instance.
SCMHelper
can be used in two different ways:- standard way: an
Activity
is used through the methodsSCMHelper.activityCreated
,SCMHelper.activityDestroyed
,SCMHelper.activityPaused
andSCMHelper.activityResumed
. - automated way: an
androidx.appcompat.app.AppCompatActivity
is used through the methodsSCMHelper.observableActivityCreated
and, if needed,SCMHelper.observableActivityDestroyed
. This is a convenient way since fewer methods are called and things are more automated but requires aAppCompatActivity
activity. In practice, this method is called in theonCreate
method of an activity.
These two ways to use
SCMHelper
are equivalent, choice is up to the developer. Sample codes are given below.Using an Activity activity:
public class MyActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SCMHelper.activityCreated(this); } @Override protected void onDestroy() { super.onDestroy(); SCMHelper.activityDestroyed(this); } @Override protected void onResume() { super.onResume(); SCMHelper.activityResumed(this); } @Override protected void onPause() { super.onPause(); SCMHelper.activityPaused(this); } @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); SCMHelper.onRequestPermissionsResult(requestCode, permissions, grantResults); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); SCMHelper.activityNewIntent(intent); } }
Using an AppCompatActivity activity:
public class MyActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SCMHelper.observableActivityCreated(this); } @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); SCMHelper.onRequestPermissionsResult(requestCode, permissions, grantResults); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); SCMHelper.activityNewIntent(intent); } }
- standard way: an
Methods¶
activityCreated¶
-
public static void
activityCreated
(Activity activity)¶ Initializes SCM backend and checks on user permissions. Starts listening to USB reader events and loads cache.
This method must be called in Main Thread.
Parameters: - activity – activity in which this method must be called, in
Activity::onCreate
.
- activity – activity in which this method must be called, in
activityDestroyed¶
-
public static void
activityDestroyed
(Activity activity)¶ Stops listening to USB reader events.
Parameters: - activity – activity in which this method must be called, in
Activity::onDestroy
.
- activity – activity in which this method must be called, in
activityNewIntent¶
-
public static void
activityNewIntent
(Intent intent)¶ Looks for NFC TAG in activity intent.
Parameters: - intent – the intent received by the activity.
activityPaused¶
-
public static void
activityPaused
(Activity activity)¶ Stops listening to BLE and NFC reader events, and saves cache.
Parameters: - activity – activity in which this method must be called, in
Activity::onPause
.
- activity – activity in which this method must be called, in
activityResumed¶
-
public static void
activityResumed
(Activity activity)¶ Starts listening to BLE and NFC reader events.
Parameters: - activity – activity in which this method must be called, in
Activity::onResume
.
- activity – activity in which this method must be called, in
observableActivityCreated¶
-
public static void
observableActivityCreated
(AppCompatActivity activity)¶ Starts to observe given activity lifecycle and initializes SCM backend.
This method must be called in Main Thread.
SCMHelper.activityCreated
,SCMHelper.activityDestroyed
,SCMHelper.activityResumed
andSCMHelper.activityPaused
are automatically called.Parameters: - activity – activity to observe.
observableActivityDestroyed¶
-
public static void
observableActivityDestroyed
(AppCompatActivity activity)¶ Stops to observe given activity lifecycle.
SCMHelper.observableActivityCreated
is assumed to be previously called with same activity. This method is automatically called in given activityonDestroy
method.Parameters: - activity – activity to stop to observe.
onRequestPermissionsResult¶
-
public static void
onRequestPermissionsResult
(int requestCode, String[] permissions, int[] grantResults)¶ Transmits request permissions result to the middleware.
Parameters: - requestCode – the request code given by
Activity.onRequestPermissionsResult(int,String[],int[])
callback. - permissions – the permissions given by
Activity.onRequestPermissionsResult(int,String[],int[])
callback. - grantResults – the grantResults given by
Activity.onRequestPermissionsResult(int,String[],int[])
callback.
- requestCode – the request code given by