I am making an application that should do the following tasks:
- image processing in a bitmap
- receive String by doing OCR(optical character recognition) in the bitmap that received from task 1
- retrieve data from the app's Room's database by searching the keyword that received from task 2
- Show the retrieved data on a TextView
I want to find a way to these 3 tasks sequentially since they are connected with each other. But i don't know how.
At first i thought that if i could just do
Bitmap b = imageProcessing(bitmap);
String keyword = ocr(b);
String data = retrievedata(keyword);
textview.setText(data);
But as I had read in many articles that's not the right way to run different tasks, because like that I run everything on the main thread
I also thought of using Executors for every different task but the issue is that by this way i won't have access to whatever i need to receive from every task. (e.x i won't be able to use the string from the task 3 to the task 4).. if i understood right
ExecutorService executor = Executors.newSingleThreadExecutor();
Handler handler = new Handler(Looper.getMainLooper());
executor.execute(() -> {
//Background work here
handler.post(() -> {
//UI Thread work here
});
});
I found this codelab that talks about WorkManager and i think that maybe is suitable for me. https://developer.android.com/codelabs/android-workmanager-java#0
I also found this tutorial about HandlerThread but I am still not sure if this is suitable for me. https://www.youtube.com/watch?v=n0mkYSjldeA
I am really confused because i am very new to android. Could someone recommend me something?