Reputation: 6556
I'm trying to implementing a parallel download using a Thread, but all my unzip process should be sequentially. As is known Intent Service enqueue all pending task so in the end of all my downloads I'm trying to start a intent service. The problem is that I'm getting the following error:
05-30 11:49:10.520: E/AndroidRuntime(18790): FATAL EXCEPTION: main
05-30 11:49:10.520: E/AndroidRuntime(18790): java.lang.RuntimeException: Unable to instantiate service br.com.facilit.target.app.android.util.UnzipService: java.lang.InstantiationException: can't instantiate class br.com.facilit.target.app.android.util.UnzipService; no empty constructor
My Download Thread:
public class DownloadService implements Runnable {
Activity controller;
boolean post;
String urlParent;
String filePath;
String destinationPath;
ResultReceiver mReceiver;
String typeDownload;
MetaDados metaDado;
int index;
boolean isResuming;
File jsonFile = new File(Constants.DEST_PATH_PARENT + Constants.JSON_FILES_PATH);
File jsonTempFile;
public DownloadService(Activity controller, boolean post, String urlParent, String filePath,
String destinationPath, ResultReceiver mReceiver, String typeDownload, int index, MetaDados metaDado,
boolean isResuming) {
this.controller = controller;
this.post = post;
this.urlParent = urlParent;
this.filePath = filePath;
this.destinationPath = destinationPath;
this.mReceiver = mReceiver;
this.typeDownload = typeDownload;
this.index = index;
this.metaDado = metaDado;
this.isResuming = isResuming;
}
@Override
public void run() {
Log.d(Constants.DOWNLOAD_AND_UNZIP_SERVICE, "Começando processo de download");
// ALL DOWNLOAD PROCESS
// THEN CALL INTENT FOR UNZIP
final Intent service = new Intent(controller.getApplicationContext(), UnzipService.class);
service.putExtra("post", false);
service.putExtra("filePath", filePath);
service.putExtra("destinationPath", destinationPath);
service.putExtra("receiver", mReceiver);
service.putExtra("typeDownload", Constants.HTML);
service.putExtra("metaDado", metaDado);
service.putExtra("isResuming", false);
controller.runOnUiThread(new Runnable() {
@Override
public void run() {
controller.startService(service);
}
});
}
}
My Unzip Intent Service:
public class UnzipService extends IntentService {
public UnzipService(String name) {
super("UnzipService");
}
@Override
protected void onHandleIntent(Intent intent) {
String filePath = intent.getStringExtra("filePath");
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(1000);
Log.d("UnzipService", "Simulando descompactação de arquivo " + filePath);
} catch (InterruptedException e) {
}
}
}
}
Manifest:
<service android:name="br.com.facilit.target.app.android.util.UnzipService"/>
Upvotes: 0
Views: 143
Reputation: 157447
as the exception reports you have no empty constructor
Change it in:
public UnzipService() {
super("UnzipService");
}
Upvotes: 3