にタスクを追加したいのですが、現在、1 つのタスクに対して正しく機能してJobIntentService queue
いる を作成しましたが、終了する前に呼び出すと機能しません。JobIntentService
enqueueWork
existing service
以下は私のJobIntentService
public class SaveImageService extends JobIntentService {
private String TAG = "SaveImageService";
private int textureViewDefaultHeight =1100;
static final int JOB_ID = 1101;
private static Context mContext;
private ResultReceiver mResultReceiver;
public static final int SHOW_RESULT = 57;
public static final String RECEIVERstr = "receiver";
public static void enqueueWork(Context context, Intent work, SaveImageReceiver saveImageReceiver) {
mContext = context;
Intent intent = work;
intent.putExtra(RECEIVERstr, saveImageReceiver);
enqueueWork(context, SaveImageService.class, JOB_ID, intent);
}
@Override
protected void onHandleWork(@NonNull Intent intent) {
Log.e(TAG, "** onHandleWork");
if (intent.hasExtra("fileUri")) {
mResultReceiver = intent.getParcelableExtra(RECEIVERstr);
Log.e(TAG, "** onHandleWork if has extra");
Uri oldUri = intent.getParcelableExtra("fileUri");
int textureViewHeight = intent.getIntExtra("textureViewHeight",textureViewDefaultHeight);
Uri tempUri = getBitmapForBatch(oldUri,textureViewHeight);
if(tempUri!=null){
Log.e(TAG, "** if(tempUri!=null){");
Bundle bundle = new Bundle();
bundle.putParcelable("ResultUri", tempUri);
if (mResultReceiver != null) {
Log.e(TAG, "** onHandleWork mResultReceiver not null");
mResultReceiver.send(SHOW_RESULT, bundle);
} else
Log.e(TAG, "** onHandleWork mResultReceiver isss null");
}else
Log.e(TAG, "** else (tempUri!=null){");
}else{
Log.e(TAG, "** onHandleWork else uri not get");
}
}
}
ユーザーが写真をクリックするたびに開始しています
Intent mIntent = new Intent(context, SaveImageService.class);
mIntent.putExtra("fileUri", fileUri);
mIntent.putExtra("textureViewHeight", textureView.getHeight());
SaveImageService.enqueueWork(context, mIntent, mSaveImageReceiver);
助けてくれてありがとう。