您可以通过 JML 使用 ObservableInteger 解决此问题。它所做的只是简单地添加数字。当它达到您想要的数量时,任务将被处理或完成。以下是如何实现它。
在您的 OnCreate 中,您只需调用将等待发生某事的侦听器
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
}
}
});
所以,现在你只需要告诉mObsInt 什么时候递增,所以在完成UploadingService 之后它将是1,然后在循环之后它将是2。
为此,只需添加这一行
mObsInt.set(mObsInt.get()+1);
实现它看起来像这样:
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:如果 uploadingProcess 有 AsyncTask ,请将 mObsInt.set(mObsInt.get()+1); 放入您的 onPostExecute 方法中
希望对你有帮助
愉快的编码