I have a thread that is downloading images in the background and need it to finish before upload starts. I have a button that starts the uploading but not sure how to check if my first thread is done/ wait for it to be done.
here is my downloading thread:
t = new Thread(new Runnable() {
// NEW THREAD BECAUSE NETWORK REQUEST WILL BE MADE THAT WILL BE A LONG PROCESS & BLOCK UI
// IF CALLED IN UI THREAD
public void run() {
try {
for (int i = 0; i < Constants2photo.IMAGES.size(); i++) {
Uri myUri = Uri.parse(Constants2photo.IMAGES.get(i).get("url"));
String fileLocation = loadPicasaImageFromGallery(myUri);
Constants2photo.IMAGES.get(i).put("fileLocation", fileLocation);
System.out.println("fileloc: " + fileLocation);
}
System.out.println("done getting files - " + Constants2photo.IMAGES);
//this part would download the image to the media store//TODO add this to a background task so sending event is faster.
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
t.start();
threads.add(t); //this is a List
The above code is just in my onactivityresult method in my class
My button code with thread #2 that needs to start after t is done:
public void submitPhotos(View view){
//convert and submit photos here
Thread t2 = new Thread(new Runnable() {
// NEW THREAD BECAUSE NETWORK REQUEST WILL BE MADE THAT WILL BE A LONG PROCESS & BLOCK UI
// IF CALLED IN UI THREAD
public void run() {
try {
for (int i = 0; i < Constants2photo.IMAGES.size(); i++) {
...
System.out.println("encoded string: " + encodedString);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
t2.start();
So where do i use join to make t2 execute only when t is done??