Home Android application finishes unexpectedly without any exception while heavy IO
Reply: 0

Android application finishes unexpectedly without any exception while heavy IO

Michał Jabłoński
Michał Jabłoński Published in 2018-02-14 08:56:50Z

My application finishes unexpectedly without throwing any exception while IO. It downloads set of about 100k small files then saves bytes to binnary file and then saves its info to DB.

Start downloading:

private void prepareObservable(List<SynchronizationFilesEntity> filesToDownload) {
    downloadingObservable = Observable.fromIterable(filesToDownload)

public void startDownloading() {
    downloadingDisposable = downloadingObservable
            .subscribe(entity -> {
            }, this::onError);


private SynchronizationFilesEntity downloadFile(SynchronizationFilesEntity entity) throws IOException {
    Response<ResponseBody> response = downloader.downloadFile(entity.getUrl());
    if (response.isSuccessful()) {
        ResponseBody responseBody = response.body();
        saveBytesToBinAndUpdateDb(responseBody, entity);

    return entity;

Writing bytes to bin is byte by byte using RandomAccessFile and InputStream. Saving to db is simple SQLite.

After processing about 300-500 mb (every file is about 10-100 kb) application stops without any error in LogCat or Alert Dialog with "application has unexpectedly stopped" or sth like that. Before changing this to RxJava, code works in AsyncTask and was doing well.

Object of class is Singleton.

EDIT: After some testing, when error occurres I see logs:

02-14 16:09:49.358 667-759/? W/InputDispatcher: channel '75fea42 com.package/com.package.uiContainer.ui.webAppContainer.WebViewActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
02-14 16:09:49.358 667-759/? E/InputDispatcher: channel '75fea42 com.package/com.package.uiContainer.ui.webAppContainer.WebViewActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
02-14 16:09:49.383 667-2490/? I/WindowState: WIN DEATH: Window{75fea42 u0 com.package/com.package.uiContainer.ui.webAppContainer.WebViewActivity}
02-14 16:09:49.442 667-1374/? I/ActivityManager: Process com.package (pid 29889) has died
02-14 16:09:49.458 667-1374/? W/ActivityManager: Force removing ActivityRecord{451c683 u0 com.package/.uiContainer.ui.webAppContainer.WebViewActivity t217}: app died, no saved state

Original package was replaced with com.package.

Just before it, application selects data from db using cursor.

String rawQuery = "SELECT Offset, Length " +
                "FROM CoursesFiles " +
                "WHERE CourseId = ? " +
                "ORDER BY Offset";
        String[] args = {String.valueOf(courseId)};

        Cursor c = connection.rawQuery(rawQuery, args);
        //some more logic here, iterating cursor 

I reduced all db cursor usages to minimum, like Dhaval Patel suggested in comments section.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298059 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO