@Override protected void onHandleIntent(Intent intent) { if (intent != null) { final String action = intent.getAction(); Utils.log("onHandleIntent " + intent.getAction()); long[] tasks_ids; try { if (action.equals(Utils.ACTION_PROCESS_TASK)) { long task_id = intent.getLongExtra(Utils.EXTRA_TASK_ID, -1); LocalTask task = DatabaseHelper.getInstance(this).getTask(task_id); final Intent result = new Intent(Utils.ACTION_RESULT_PROCESS_TASK); result.putExtra(Utils.EXTRA_TASK_ID, task.getLocalId()); if (isOnline()) { processOptions(task); task.persistBlocking( new PersistCallback() { @Override public void run() { if (cache_unshorten != null) { result.putExtra(Utils.EXTRA_CACHE_UNSHORTEN, cache_unshorten); } if (cache_titles != null) { result.putExtra(Utils.EXTRA_CACHE_TITLES, cache_titles); } LocalBroadcastManager.getInstance(GoogleTasksService.this) .sendBroadcast(result); } }); } else { tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS); revertTaskToReady(tasks_ids); LocalBroadcastManager.getInstance(this).sendBroadcast(result); } } else if (action.equals(Utils.ACTION_SEND_TASKS)) { if (isOnline()) { tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS); if (tasks_ids.length == 1) { DatabaseHelper databaseHelper = DatabaseHelper.getInstance(this); LocalTask task = databaseHelper.getTask(tasks_ids[0]); handleActionSend(task); } else { handleActionSendMultiple(tasks_ids); } stopForeground(true); } else { tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS); revertTaskToReady(tasks_ids); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .notify( NOTIFICATION_SEND_LATER, buildNotification(NOTIFICATION_SEND_LATER).build()); } } else if (action.equals(Utils.ACTION_LIST_TASKS)) { handleActionList(); } else if (action.equals(Utils.ACTION_REMOVE_TASKS)) { handleActionRemove(intent.getStringArrayListExtra(Utils.EXTRA_TASKS_IDS)); } } catch (UserRecoverableAuthIOException userRecoverableException) { Utils.log(Log.getStackTraceString(userRecoverableException)); stopForeground(true); tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS); revertTaskToReady(tasks_ids); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .notify( NOTIFICATION_NEED_AUTHORIZE, buildNotification(NOTIFICATION_NEED_AUTHORIZE).build()); } catch (IOException ioException) { Utils.log(Log.getStackTraceString(ioException)); if (action.equals(Utils.ACTION_SEND_TASKS)) { tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS); stopForeground(true); revertTaskToReady(tasks_ids); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .notify(NOTIFICATION_ERROR, buildNotification(NOTIFICATION_ERROR).build()); } else { Intent broadcast = new Intent(Utils.ACTION_LIST_TASKS); broadcast.putExtra(Utils.EXTRA_ERROR_TEXT, getString(R.string.txt_error_list)); LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast); } } catch (NullPointerException npe) { tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS); Utils.log(Log.getStackTraceString(npe)); stopForeground(true); revertTaskToReady(tasks_ids); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .notify( NOTIFICATION_NEED_AUTHORIZE, buildNotification(NOTIFICATION_NEED_AUTHORIZE).build()); } } }