Resuming Resource Downloading

One can set up in the mobile application parameters for resuming resource downloading with saving the state:

If resource downloading has failed or mobile platform server connection is lost, the mobile application keeps requesting resource.

To get table data of parameter cache from mobile platform server with loading to database, create the TableStreamActivity application, which uses the tableStream method implemented in the RequestAPI unit.

NOTE. The application is identical to the TableStreamSapActivity application.

Before creating an application make sure that the resource is available in PostgreSQL data source. The table consists of three columns containing information about fruits: id, name, description.

The TableStreamActivity application includes one screen and a button:

To view application work results, use the interactive example:

Click the TABLESTREAM button.

public class TableStreamActivity extends AppCompatActivity {
    private static final String MY_URL = "http://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 MY_RESOURCE = "Leonid_postgreSQL";
    private static final String TAG = "TableStreamActivity";
 
    private HyperHive hyperHive;
    private TextView textView;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_table_stream);
        textView = findViewById(R.id.text_view_table_stream);
 
        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();
        authentication();
    }
 
    public void authentication() {
        boolean status = hyperHive.authAPI.auth(MY_LOGIN, MY_PASSWORD, true).execute().isOk();
        showStatus(status);
    }
 
    public void tableStream(View view) {
        // Create parameters for the TableStreamCallParams request
        TableStreamCallParams tableStreamCallParams = new TableStreamCallParams();
        String params = "{\"upsert_rows\": null ,\"delete_ids\": null}"; // do not update and delete rows
        tableStreamCallParams.setData(params);
        tableStreamCallParams.setRetryCount(10);
        tableStreamCallParams.setRetryIntervalSec(1);
 
        // Send the tableStream request
        hyperHive.requestAPI.tableStream(MY_RESOURCE, tableStreamCallParams).execute(); // pass table name
 
        // Get table from data source
        TableStreamStatus queryRequest = hyperHive.databaseAPI.getTablesName(MY_RESOURCE, tableStreamCallParams.getData(), TableStreamStatus.class).execute();
        // queryParams...statements contains the list of SELECT requests for corresponding params parameters
        // this example contains one possible option
        String response = hyperHive.databaseAPI.query(queryRequest.request.source.database.statements[0], StatusSelectTable.class).execute().toString();
        textView.setText(response);
    }
 
    public void showStatus(boolean status) {
        Log.d(TAG, "auth: " + status);
        Toast.makeText(this, "auth: " + status, Toast.LENGTH_LONG).show();
    }
}
 
class TableStreamStatus extends BaseStatus {
    @Expose
    @SerializedName("request")
    public Request request;
}
 
class Request {
    @Expose
    @SerializedName("source")
    public Source source;
}
 
class Source {
    @Expose
    @SerializedName("database")
    public Database database;
}
 
class Database {
    @Expose
    @SerializedName("name")
    public String name;
    @Expose
    @SerializedName("statements")
    public String[] statements;
}

See also:

Examples of Android Framework Use | Examples of Working with Resources