title: Best practices for pubnub on android
body: <p>I'm using pubnub as a publish/subscribe channel between an android app and a server.
  Currently I'm thinking of how I will implement this.</p>
  
  <p>I'm using the provided library for android (<a href="https://github.com/pubnub/pubnub-api/tree/master/android">https://github.com/pubnub/pubnub-api/tree/master/android</a>) but I think there will be some problems with the application lifecycle if I use it like it is now. (Correct me if i'm wrong)</p>
  
  <p>I was thinking of implementing it as a service</p>
  
  <p>What I want</p>
  
  <ul>
  <li><p>The service has to keep on running until an hour (negotiable) after the last app usage. That's because we want to have notifications when a message comes in, but the app is not the currently used app.</p></li>
  <li><p>How do i stop the service after one hour of non-activity of the app? Probably Android will kill it, but I want some control.</p></li>
  <li><p>The Service must be able to trigger the app to change it's interface when specific messages come in (I was thinking of sending intents from the service when we receive a pubnub message?), pubnub will send data to the service, so I need a way to pass this data to the application (probably save it in a Bundle in the intent?)</p></li>
  <li><p>I need to listen to multiple pubnub channels (max 2 at the same time), I think I will have to do this in multiple instances of this service?</p></li>
  </ul>
  
  <p>I think I will do it like this:</p>
  
  <ul>
  <li><p>Create a service that's started when the app starts</p></li>
  <li><p>Let the service listen to a pubnub channel</p></li>
  <li><p>When a message comes in, send an intent and use the intent filters</p></li>
  <li><p>implement broadcasthandlers to listen to these internal intents</p></li>
  </ul>
  
  <p>Is this the right way to do this? any hints?</p>