2013-05-30 3 views
0

Я пытаюсь реализовать параллельную загрузку с использованием Thread, но весь мой процесс распаковки должен быть последовательным. Как известно, Intent Service завершает всю ожидающую задачу, поэтому в конце всех моих загрузок я пытаюсь запустить услугу намерения. Проблема заключается в том, что я получаю следующее сообщение об ошибке:Возможно ли инициировать услугу Intent из потока?

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 

Мой Скачать тему:

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); 

        } 
       }); 
    } 
} 

Мой Распакуйте Намерение Услуги:

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"/> 

ответ

3

как отчеты об исключениях, которые у вас есть no empty constructor Изменить его в:

public UnzipService() { 
     super("UnzipService"); 
} 
Смежные вопросы