@Test public void computation_should_send_intent_with_computer_result() { final List<Intent> receivedIntents = new ArrayList<>(); BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { receivedIntents.add(intent); } }; IntentFilter filter = new IntentFilter(); filter.addAction(Computation.RESULT_INTENT_ACTION); RuntimeEnvironment.application.registerReceiver(broadcastReceiver, filter); service.onHandleIntent(new Intent()); assertEquals(1, receivedIntents.size()); Intent intent = receivedIntents.get(0); assertTrue(intent.hasExtra(Computation.RESULT_VALUE_INTENT_EXTRA_KEY)); }
@Override protected void onHandleIntent(Intent intent) { Intent resultIntent = new Intent(RESULT_INTENT_ACTION); Integer result = new Computer().compute(); resultIntent.putExtra(RESULT_VALUE_INTENT_EXTRA_KEY, result); sendBroadcast(resultIntent); }
Computation extends IntentService { @Override protected void onHandleIntent(Intent intent) { Intent resultIntent = new Intent(RESULT_INTENT_ACTION); Integer result = new Computer().compute(); resultIntent.putExtra(RESULT_VALUE_INTENT_EXTRA_KEY, result); sendBroadcast(resultIntent); } }
Computation extends IntentService { @Override protected void onHandleIntent(Intent intent) { Intent resultIntent = new Intent(RESULT_INTENT_ACTION); Integer result = new Computer().compute(); resultIntent.putExtra(RESULT_VALUE_INTENT_EXTRA_KEY, result); sendBroadcast(resultIntent); } Computation(); }
Computation extends IntentService { @Override protected void onHandleIntent(Intent intent) { Intent resultIntent = new Intent(RESULT_INTENT_ACTION); Integer result = new Computer().compute(); resultIntent.putExtra(RESULT_VALUE_INTENT_EXTRA_KEY, result); sendBroadcast(resultIntent); } Computation();  }
Computation extends IntentService { @Override protected void onHandleIntent(Intent intent) { Intent resultIntent = new Intent(RESULT_INTENT_ACTION); Integer result = new Computer().compute(); resultIntent.putExtra(RESULT_VALUE_INTENT_EXTRA_KEY, result); sendBroadcast(resultIntent); } Computation();  static final String RESULT_INTENT_ACTION; static final String RESULT_VALUE_INTENT_EXTRA_KEY; }