Source:
<code>public void onMessageArrivedEvent(String jobId, String peer, String messageText) { RCLogger.i(TAG, "onMessageArrivedEvent(): id: " + jobId + ", peer: " + peer + ", text: " + messageText); HashMap<String, String> parameters = new HashMap<String, String>(); String peerSipUri = peer.replaceAll("^<", "").replaceAll(">$", ""); if (messageIntent != null) { if (isServiceAttached) { audioManager.playMessageSound(); messageIntent.setAction(ACTION_INCOMING_MESSAGE); messageIntent.putExtra(EXTRA_DID, peerSipUri); messageIntent.putExtra(EXTRA_MESSAGE_TEXT, messageText); if (!this.parameters.containsKey(ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS) || !(Boolean) this.parameters.get(ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS)) { PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, messageIntent, PendingIntent.FLAG_UPDATE_CURRENT); try { pendingIntent.send(); } catch (PendingIntent.CanceledException e) { throw new RuntimeException("Pending Intent cancelled", e); } } else { Intent testIntent = new Intent(RCDevice.ACTION_INCOMING_MESSAGE); testIntent.putExtra(EXTRA_DID, peerSipUri); testIntent.putExtra(EXTRA_MESSAGE_TEXT, messageText); sendBroadcast(testIntent); } } else { if (mHandler == null) { mHandler = new Handler(); } <START> stopRepeatingTask(); <END> startRepeatingTask(); messageTimeOutInterval = messageTimeOutIntervalLimit; onNotificationMessage(peerSipUri, messageText); } } else { RCLogger.w(TAG, "onMessageArrivedEvent(): Incoming text message event is discarded because Intent is missing for incoming text messages. To receive such event please initialize RCDevice with a RCDevice.ACTION_INCOMING_MESSAGE intent"); } }</code><technical_language>simplify this timer? a bit difficult call start stop. a RCConnection.java timeoutHandler example</technical_language>

Target:
public void onMessageArrivedEvent(String jobId, String peer, String messageText) { RCLogger.i(TAG, "onMessageArrivedEvent(): id: " + jobId + ", peer: " + peer + ", text: " + messageText); String peerSipUri = peer.replaceAll("^<", "").replaceAll(">$", ""); if (messageIntent != null) { if (isServiceAttached) { audioManager.playMessageSound(); messageIntent.setAction(ACTION_INCOMING_MESSAGE); messageIntent.putExtra(EXTRA_DID, peerSipUri); messageIntent.putExtra(EXTRA_MESSAGE_TEXT, messageText); if (!this.parameters.containsKey(ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS) || !(Boolean) this.parameters.get(ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS)) { PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, messageIntent, PendingIntent.FLAG_UPDATE_CURRENT); try { pendingIntent.send(); } catch (PendingIntent.CanceledException e) { throw new RuntimeException("Pending Intent cancelled", e); } } else { Intent testIntent = new Intent(RCDevice.ACTION_INCOMING_MESSAGE); testIntent.putExtra(EXTRA_DID, peerSipUri); testIntent.putExtra(EXTRA_MESSAGE_TEXT, messageText); sendBroadcast(testIntent); } } else { if (messageTimeoutHandler == null) { messageTimeoutHandler = new Handler(); } startRepeatingTask(); messageTimeOutInterval = messageTimeOutIntervalLimit; onNotificationMessage(peerSipUri, messageText); } } else { RCLogger.w(TAG, "onMessageArrivedEvent(): Incoming text message event is discarded because Intent is missing for incoming text messages. " + "To receive such event please initialize RCDevice with a RCDevice.ACTION_INCOMING_MESSAGE intent"); } }