Skip to content

Instantly share code, notes, and snippets.

@cwdoh
Last active March 6, 2019 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwdoh/f8b720dc428cfbb95b27cb83f0bc968a to your computer and use it in GitHub Desktop.
Save cwdoh/f8b720dc428cfbb95b27cb83f0bc968a to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.JobIntentService;
import android.util.Log;
import android.widget.Toast;
import
/**
* Example implementation of a JobIntentService.
*/
public class UpdateJobIntentService extends JobIntentService {
static final int JOB_ID = 1000;
static final String WORK_DOWNLOAD_ARTWORK = ".DOWNLOAD_ARTWORK";
ArtworkDownloader mDownloader;
static void enqueueWork(Context context, Intent work) {
enqueueWork(context, Update.class, JOB_ID, work);
}
@Override
public void onCreate() {
super.onCreate();
mDownloader = ArtworkDownloader.getSequencialDownloader();
}
@Override
protected void onHandleWork(Intent intent) {
// enqueueWork()에 의해 적재된 인텐트는 여기로 전달됩니다.
if (WORK_DOWNLOAD_ARTWORK.equals(intent.getAction())) {
mDownloader.download(intent.getStringExtra("URL"))
}
}
@Override
public boolean onStopCurrentWork() {
// 현재 처리 중인 동작들을 중지해야 할 경우
return !mDownloader.isFinished();
}
}
@sanjay90chd
Copy link

sanjay90chd commented Sep 6, 2017

How to call JobIntentService from activity.
could you give me complete example for this?

@smsrobot
Copy link

smsrobot commented Sep 6, 2017

onHandleWork does not get Called on Android O (SDK 26), while on sdk < 26 it works
why ?

@eshaanb
Copy link

eshaanb commented Sep 12, 2017

@smsrobot I am having the same issue in my own codebase. Let me know if you find a solution..

@LaurieScheepers
Copy link

Per Android documentation, a subclassed JobIntentService should be started by calling the static enqueueWork() method.

@bradroid
Copy link

Line 16, what is Update.class? Should it be UpdateJobIntentService.class instead?

@tintinscorpion
Copy link

onHandleWork does work. If your code is having this ,
@OverRide
public IBinder onBind(Intent intent) {
return null;
}
remove it and it will work.

@NoushadMMA
Copy link

onHandleWork does work. If your code is having this ,
@OverRide
public IBinder onBind(Intent intent) {
return null;
}
remove it and it will work.

why? how?

@DivyaValsanNP
Copy link

How to call jobintentservice class from activity?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment