You can solve this with ObservableInteger
by JML. What it does is simply adds numbers. When it reaches the number you want, a task will take process or will finish. Here is how to implement it.
In your OnCreate
you just call the listener that will be waiting until something happens
private ObservableInteger mObsInt;
//Listener
mObsInt = new ObservableInteger();
mObsInt.set(0);
mObsInt.setOnIntegerChangeListener(new OnIntegerChangeListener()
{
@Override
public void onIntegerChanged(int newValue)
{
if (mObsInt.get()==1) {
Log.e("Uploading Process finished"," mObsInt 1");
Log.e("Download1"," Finished first process ");
//Here you can launch your loop method
}
if (mObsInt.get()==2) {
//Here it will tell you that the loop has finished
}
}
});
So, now you only need to tell mObsInt
when to increment, so after finishing UploadingService
it will be 1 and then after the loop it will be 2.
To do this add just this line
mObsInt.set(mObsInt.get()+1);
Implementing it would look like this:
public class UploadingService extends Service {
public UploadingService() {
//process
mObsInt.set(mObsInt.get()+1); //now mObsInt will be 1
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
for(int i = 0; i < mArrayUri.size(); i++){
*********
//firebase uploading codes
************
/*what code ??? wait until uploading
is complete than for loop iterate new iteration
*/
mObsInt.set(mObsInt.get()+1); //Now mObsInt will be 1 + 1 = 2 , so the code in your onCreate will manage what to do
}
}
}
PS: if the uploadingProcess has an AsyncTask
, put mObsInt.set(mObsInt.get()+1);
in your onPostExecute
method
Hope it helps
Happy coding