I have a project I am working on where I need to improve my knowledge on Threads.
Scenario: I have an Activity which calls a method Which use uses a thread:
Object soapResponse = soaphttp.fetchNextCatalogueRange(0, numberOfItems);
In the soaphttp class I have:
Thread soapThread = new Thread(new Runnable()
{
private Object serverResponse = new Object();
public void run()
{
// Do network stuff here
}
});
soapThread.start();
try
{
// crude synchronisation
soapThread.join();
}
The problem Using join() blocks the UI thread. If I dont use join() I get null pointer exceptions (data sync errors)
The Challenge: In my activity I would like to do stuff on the UI thread while the soaphttp class is fetching data and then sync i.e tell the UI thread that the data is ready. for example display a progress bar .. which will terminate when the data has finished being fetched.
How can I do this without having to use AsyncTask ?