What is the difference between map and flatmap in RxJava?

It depends on the Scheduler. If the operations occur on an UI thread, it is okay. I can show an example in one of my applications I am working on:

...
return getDownloadPagesOfDownloadChapter(downloadChapter)
            .filter(new Func1<List<DownloadPage>, Boolean>() {
                @Override
                public Boolean call(List<DownloadPage> downloadPages) {
                    return downloadPages.size() != 0;
                }
            })
            .switchIfEmpty(
                    mAizobanRepository.pullImageUrlsFromNetwork(downloadChapter.getSource(), downloadChapter.getUrl())
                            .subscribeOn(Schedulers.newThread())
                            .toList()
                            .flatMap(new Func1<List<String>, Observable<List<DownloadPage>>>() {
                                @Override
                                public Observable<List<DownloadPage>> call(List<String> imageUrls) {
                                    return createDownloadPagesOfDownloadChapter(downloadChapter, imageUrls);
                                }
                            })
                            .doOnNext(new Action1<List<DownloadPage>>() {
                                @Override
                                public void call(List<DownloadPage> downloadPages) {
                                    updateDownloadChapterTotalPageCount(downloadChapter, downloadPages.size());
                                }
                            })
            )
            .doOnNext(new Action1<List<DownloadPage>>() {
                @Override
                public void call(List<DownloadPage> downloadPages) {
                    totalDownloadCount.set(downloadPages.size());
                }
            })
            .flatMap(new Func1<List<DownloadPage>, Observable<File>>() {
                @Override
                public Observable<File> call(List<DownloadPage> downloadPages) {
                    return Observable.from(downloadPages)
                            .filter(new Func1<DownloadPage, Boolean>() {
                                @Override
                                public Boolean call(DownloadPage downloadPage) {
                                    return downloadPage.getFlag() != DownloadUtils.FLAG_COMPLETED;
                                }
                            })
                            .flatMap(new Func1<DownloadPage, Observable<File>>() {
                                @Override
                                public Observable<File> call(final DownloadPage downloadPage) {
                                    return mNetworkService.getResponse(downloadPage.getUrl(), null, null)
                                            .flatMap(new Func1<Response, Observable<File>>() {
                                                @Override
                                                public Observable<File> call(Response response) {
                                                    String fileDirectory = downloadPage.getDirectory();
                                                    String fileName = downloadPage.getName();
                                                    String fileType = response.body().contentType().subtype();
                                                    BufferedSource fileData = response.body().source();

                                                    return saveBufferedSourceToDirectory(fileData, fileDirectory, fileName + "." + fileType);
                                                }
                                            })
                                            .doOnCompleted(new Action0() {
                                                @Override
                                                public void call() {
                                                    currentDownloadCount.incrementAndGet();
                                                }
                                            });
                                }
                            });
                }
            })
...
/r/androiddev Thread