service - Best practices for pubnub on android -
i'm using pubnub publish/subscribe channel between android app , server. i'm thinking of how implement this.
i'm using provided library android (https://github.com/pubnub/pubnub-api/tree/master/android) think there problems application lifecycle if use now. (correct me if i'm wrong)
i thinking of implementing service
what want
the service has keep on running until hour (negotiable) after last app usage. that's because want have notifications when message comes in, app not used app.
how stop service after 1 hour of non-activity of app? android kill it, want control.
the service must able trigger app change it's interface when specific messages come in (i thinking of sending intents service when receive pubnub message?), pubnub send data service, need way pass data application (probably save in bundle in intent?)
i need listen multiple pubnub channels (max 2 @ same time), think have in multiple instances of service?
i think this:
create service that's started when app starts
let service listen pubnub channel
when message comes in, send intent , use intent filters
implement broadcasthandlers listen these internal intents
is right way this? hints?
you have excellent set of questions detailed points talk in answer. using android , interested in conventions , best practices pubnub publish/subscribe scenarios.
your use case common , best ways build apps vary dependent on application needs. have right idea , have asked right questions. needed sample code , direction started on implementing specifics of application needs. define needs in list:
- connect/disconnect ability.
- always-on background service can send/receive data , notify other apps via android intents.
- connecting multiple pubnub channels @ same time.
so started provide direct links examples , methods:
- create service started when when android boots: https://github.com/pubnub/pubnub-api/blob/0dfd8028b803332f5641adc909b1a26f87bd7ff1/android/pubnubandroid/src/com/aimx/androidpubnub/bootreceiver.java
- unsubscribe/disconnect example code when want stop listening on pubnub channel: https://github.com/pubnub/pubnub-api/blob/0dfd8028b803332f5641adc909b1a26f87bd7ff1/android/pubnubandroid/src/com/aimx/androidpubnub/mainactivity.java - listening multiple channels easy placing blocking pubnub.subscribe() method inside thread.
regarding thoughts - is right way it:
- create service that's started when app starts
- let service listen pubnub channel.
- when message comes in, send intent , use intent filters.
- implement broadcasthandlers listen these internal intents.
Comments
Post a Comment