Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How use @WorkerThread annotation in android project?

Before I used some way for call code in non ui thread (AsyncTask, Loader etc) . But now I try to use @WorkerThread annotation for method, it called some network request

@WorkerThread
    public void downloadInFile(final String url, final String rootDirectory, final OnFinishLoadAudioInFile onFinishLoadAudioInFile,
                               final OnUpdateLoadAudio onUpdateLoadAudio) {
        final String fileName = URLUtil.guessFileName(url,  null, null);
        downloadFile(url, rootDirectory + File.pathSeparator + fileName, onFinishLoadAudioInFile, onUpdateLoadAudio);
    }

, and have android.os.NetworkOnMainThreadException. How use @WorkerThread annotation correctly?

like image 836
mlevytskiy Avatar asked Nov 11 '15 11:11

mlevytskiy


1 Answers

WorkerThread annotation is only to add a requirement of calling thread not for automatically using a specific thread. You still have to do the threading.

like image 156
davidpetter Avatar answered Oct 29 '22 06:10

davidpetter