android-service

Accessing Android Service Through Global Object

I've a simple service that several of my activities need to access. The standard approach seems to be: Create ServiceConnection to specify what to do after binding [with the service object] call bindService with ServiceConnection But that requires calling bindService at least once per activity. What if I call bindService exactly once...

Create only one instance of Service (Android)

How can I make sure that only one instance of Service is created? I have checked some functions with logging (WeatherService is the class who extends Service): Log.i(TAG, "Start Id:" + WeatherService.this.hashCode()); Log.i(TAG, "End Id:" + WeatherService.this.hashCode()); It gives different hash codes even when I am sure that the s...

Android service error handling

What is best way for services error handling? For example, I have service which get some information from Internt, I want show to user some dialog with message when connectivity is bad. Or if I have some Util class for parse HTML that used by my service and exception occures in this Util class. How to show dialog? As I know DialogBuilder...

How to handle notifications in an Android Activity

I have an Activity that will query a RESTful API every x seconds (polls using a handler). The results of the GET are used to update a ListView. This is done using an AsyncTask. I want to put a Notification in the Notification bar when certain criteria are met in the new data. Everything I have read up to this point has suggested that...

How to send an ArrayList of custom objects in a Bundle

I have an application that uses a service to create an ArrayList of custom objects (MyObject) every x seconds. I then want my Activity to obtain this ArrayList. I'm currently planning on having the Service send a message to the Activity's handler every time it finishes the query for the data. I want the message to the Handler to conta...

Suppress notifications from a service if activity is running

I have an Activity and Service that work together in my application. I've configured the service as a remote service (implemented AIDL) so it will keep running even when the Activity isn't visible. The service is responsible for polling a server for data and sending alert notifications when certain criteria are met. I do not want the ...

Android: Instantiate a Handler in a TimerTask within a Service

I'm trying to use a service to make a regular call to my API. The asynchronous class I use to make external HTTP calls returns information to a handler which is passed in. A simplified version below dies on the line where the Handler is instantiated (without a stack trace). Any idea why? Is there a better way I should be doing this? pa...

Change the TypeFace in an Android TextView from a Service

I'm creating a notification bar view from within a service by constructing a RemoteViews object with an XML layout file. I'd like to be able to change the typeface within this view according to a preference that the user selects. I can't seem to find a way to be able to change the typeface of a TextView without being in an activity whi...