August 26, 2018

How to run background service in Oracle MAF

In mobile apps, we often need some services to run in the background to do tasks like fetching or updating data from a server, sync local data with a server, invoking APIs etc.
In this post, we will see how to run a task in the background of a mobile app developed using Oracle MAF.

There is a default utility available in Oracle MAF to run java code in background threads which is MafExecutorService. It has a method execute() to run java runnable on a background thread in the context of the calling thread's MAF feature context. The syntax of the method is like

MafExecutorService.execute(new Runnable()
{
public void run()
{
         //Invoke your methods here     
}
});

If you update any data change events in the background, invoke below method to make it effective.

AdfmfJavaUtilities.flushDataChangeEvent();