Q:

Updating Image upload complete status in database using retrofit and rxjava

I am using Rxjava in conjunction with Retrofit. I want to update status of that image as completed in android database. So the real question is what if second image is uploaded first and after that first is uploaded?. Is onNext() is called sequentially as a images in queue gets executed or the images are uploaded in asynchronous manner. I want to know the required solution for this approach. My code so far is as follows.
tisImageEntities = SelectQuery.getImageByStatus(mContext);

    tisImageCount = 0;
    Observable.fromIterable(tisImageEntities)
            .map(tisImageEntity -> new TisImageUploadEntity(tisImageEntity.projectId,
                    tisImageEntity.imagePath.substring(tisImageEntity.imagePath.lastIndexOf("/") + 1), "fit.jpg",
                    tisImageEntity.detail, tisImageEntity.imageType,
                    getBase64EncodedString(tisImageEntity.imagePath)))
            .filter(tisImageUploadEntity -> null!=tisImageUploadEntity.Content)
            .flatMap(tisImageUploadEntity -> hitachiRetrofitApi.uploadTisImages(tisImageUploadEntity))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(new DisposableObserver<ResponseBody>() {

                @Override
                public void onNext(ResponseBody responseBody) {
                    try {
                        String response = responseBody.string().toString();
                        UpdateQuery.updateTisImageStatus(mContext,tisImageEntities.get(tisImageCount).projectId); // here is image staatus updated correctly??
                        tisImageCount++;
                        Log.d(TAG, "on next for update entity" + response);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onError(Throwable e) {
                    e.printStackTrace();
                    cancleProgressDialog();
                }

                @Override
                public void onComplete() {
                    Log.d(TAG, "on complete for update entity");
                    cancleProgressDialog();
                }
            });

So in onNext() the update query right? and is it updating the status sequentially? If not then please correct me

A:

flatMap() does not retain the order, so if you will execute multiple requests 
 results will not be emitted sequentially but by result arrived order. 
BTW, you should apply io scheduler to the returned Observable at the flatMap() (hitachiRetrofitApi.uploadTisImages(tisImageUploadEntity)) to get parallelism.
for preserving the order you can use concatMapEager() operator, which will gain you parallelism but will preserve the order of source items.
Additionally, just a suggestion, you have different option, as what you are trying to get here is to collect the request result along with the matching request image entity, you can use flatMap() overload with resultSelector param, with this way, you can send down the stream a pair of the result with the matching image entity, update the db with doOnNext(), and map just the result ResponseBody for the Subscriber to handle it.
 Observable.fromIterable(tisImageEntities)
            .map(tisImageEntity -> new TisImageUploadEntity(tisImageEntity.projectId,
                    tisImageEntity.imagePath.substring(tisImageEntity.imagePath.lastIndexOf("/") + 1), "fit.jpg",
                    tisImageEntity.detail, tisImageEntity.imageType,
                    getBase64EncodedString(tisImageEntity.imagePath)))
            .filter(tisImageUploadEntity -> null != tisImageUploadEntity.Content)
            .flatMap(tisImageUploadEntity -> hitachiRetrofitApi.uploadTisImages(tisImageUploadEntity)
                            .subscribeOn(Schedulers.io()),
                    (tisImageUploadEntity, responseBody) -> Pair::new
            )
            .doOnNext(pair -> UpdateQuery.updateTisImageStatus(mContext, pair.first.projectId))
            .map(pair -> pair.second)
            .subscribeOn(Schedulers.io());

