IntentService is the right choice when we need to start and cancel the process during the execution?

115 Views Asked by At

I need to read selected file from external storage in background and then using Universal Image Loader download images, while during the process of reading file from external storage or during the image download process user should have a option to cancel that process by choosing another file to read from external storage and then download images. I use IntentService to read file from external storage startService() while when I need to cancel the current reading process and start the process for the selected file,is that a right approach? or I need to use HandlerThread/ Service/Thread

private void startResService() {
   myServiceIntent = new Intent(activity, ResService.class);
   stopResService();
   mServiceIntent.putExtra("cancelDownload", false);
   startService(mServiceIntent);
}

 private void stopResService() {
    mServiceIntent = new Intent(this,ResService.class);
    mServiceIntent.putExtra("cancelDownload", true);
    startService(myServiceIntent);
}




 private void onHandleIntent(Intent intent) {
    Bundle bundle = intent.getExtras();
    boolean isCanceled = false;
    if (bundle != null) {
        isCanceled = bundle.getBoolean("cancelDownload");
    }

    if (!isCanceled) {
        readRes();
    }
}
0

There are 0 best solutions below