Example of Synchronous and Asynchronous Working with Framework

A request can e executed synchronously and asynchronously:

To execute synchronous or asynchronous authentication at mobile platform server, create the AsynchronousRequestActivity application, which uses the auth method implemented in the AuthAPI unit.

The AsynchronousRequestActivity application includes one screen and buttons:

To view application work results, use the interactive example:

Click any button

public class AsynchronousRequestActivity extends AppCompatActivity {
   private static final String MY_URL = "https://testmasterfmp.fsight.cloud/";
   private static final VersionAPI MY_VERSION_API = VersionAPI.V_1;
   private static final String MY_ENVIRONMENT = "Leonid_environment";
   private static final String MY_PROJECT = "Leonid_project";
   private static final String MY_VERSION = "v1";
   private static final String MY_LOGIN = "Leonid";
   private static final String MY_PASSWORD = "123123";
   private static final String TAG = "AsynchronousRequest";
 
   private HyperHive hyperHive;
 
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_asynchronous_request);
 
       Handler uiHandler = new Handler();
 
       hyperHive = new HyperHiveState(getApplicationContext())
               .setHostWithSchema(MY_URL)
               .setApiVersion(MY_VERSION_API)
               .setEnvironmentSlug(MY_ENVIRONMENT)
               .setProjectSlug(MY_PROJECT)
               .setVersionProject(MY_VERSION)
               .setHandler(uiHandler)
               .buildHyperHive();
   }
 
   // Execute authentication method synchronously
   public void authenticationSynchronous(View view) {
       boolean status = hyperHive.authAPI.auth(MY_LOGIN, MY_PASSWORD, true).execute().isOk();
       showStatus(status);
   }
 
   // Execute authentication method asynchronously
   public void authenticationAsynchronous(View view) {
       // Implement the Callback anonymous interface
       hyperHive.authAPI.auth(MY_LOGIN, MY_PASSWORD, true).enqueue(new Callback<basestatus>() {
           @Override
           // Get execution status
           public void onResponse(Call<basestatus> call, BaseStatus baseStatus) {
               showStatus(baseStatus.isOk());
           }
 
           @Override
           public void onFailure(Call<basestatus> call, Throwable throwable) {
               Log.d(TAG, "onFailure: ");
           }
       });
   }
 
   public void showStatus(boolean status) {
       Log.d(TAG, "auth: " + status);
       Toast.makeText(this, "auth: " + status, Toast.LENGTH_LONG).show();
   }
}

See also:

Examples of Android Framework Use