If your service is called only from your application, and you can make it single, try the following:
public class FileDownloaderService extends Service implements FileDownloader {
private static FileDownloaderService instance;
public FileDownloaderService () {
if (instance != null) {
throw new IllegalStateException("This service is supposed to be a singleton");
}
}
public static FileDownloaderService getInstance() {
return instance;
}
@Override
public void onCreate() {
instance = this;
}
@Override
public IBinder onBind(@SuppressWarnings("unused") Intent intent) {
return null;
}
@Override
public void downloadFile(URL from, File to, ProgressListener progressListener) {
new Thread(new Runnable() {
@Override
public void run() {
}
}).start();
}
}
. downloadFile(), .
, . , ProgressListener. :
public interface ProgressListener {
void startDownloading();
void downloadProgress(int progress);
void endOfDownload();
void downloadFailed();
}
( , , ).