Code example for ResultReceiver

Methods: send

0
	protected void onHandleIntent(Intent intent) {
		final ResultReceiver receiver = intent.getParcelableExtra("receiver");
		String command = intent.getStringExtra("command");
		Bundle bundle = new Bundle();
		if (command.equals("query")) {
			receiver.send(STATUS_RUNNING, Bundle.EMPTY);
			DataSource dataSource = new DataSource(getApplicationContext());
			try { 
				final ISipgateAPI sipgate = new SipgateXmlRpcImpl();
				dataSource.open(false);
 
				queryAccount(sipgate, dataSource);
				receiver.send(STATUS_UPDATED_ACCOUNT, bundle);
 
				queryCalls(sipgate, dataSource);
				receiver.send(STATUS_UPDATED_CALLS, bundle);
			} catch (Exception e) {
				Log.e("QueryService", "Error when updating", e);
 
				if (e instanceof AuthenticationException) {
					bundle.putString(Intent.EXTRA_TEXT, e.getMessage());
					receiver.send(STATUS_NOT_AUTHENTICATED, bundle);
				} else { 
					bundle.putString(Intent.EXTRA_TEXT, e.toString());
					receiver.send(STATUS_ERROR, bundle);
				} 
			} finally { 
				dataSource.close();
			} 
		} 
		receiver.send(STATUS_FINISHED, Bundle.EMPTY);
		this.stopSelf();
	} 
 
	private void queryCalls(final ISipgateAPI sipgate,
			final DataSource dataSource) {