Android :: How To Create Service With Callbacks
Jul 7, 2010
I'm working on a service for my application whose purpose is to allow easy access to various web services we are running. The service is used to maintain a login state across any applications that want to use it so the user only has to log in once when the service is first started.
What is the best way to go about making the service run asynchronously and call back to the application when it is finished. Currently I am using static classes that extend Thread such as
CODE:.....
And to make it easy to call
CODE:....................
But these functions can only be called by my own application. I want anyone to be able to make a one or two line function call and be able to handle the response easily, preferably in a simple callback method.
I figure it has to be done using Intents to start the Threads, but if I do that I can't pass a callback.
View 2 Replies
Sep 18, 2010
I have an android application. Based on the current geo location of user, I want to fetch some remote data in background and store it. My implementation is: At specific interval a alarm fires up my service. Service uses an anonymous class to query current location and registers a locationListener callback. On call of onLocationChanged() I initiate the remote data fetch from server.
However once my service is done registering the location listener using anonymos class, it returns as expected; as it doesn't wait for callback to happen before finishing. Since callback takes some time and makes a call when service has already returned, it throws an error saying: java.lang.RuntimeException: Handler{43e82510} sending message to a Handler on a dead thread
Which is quite understandable. One quick workaround for me now is that I can use getLastKnownLocation from locationManager as that doesn't respond back by callback; but what if I do want the latest location right now, in a service and not activity? How can I wait for callback to happen and stop my service from returning.
Also, at what point does lastKnownlocation gets updated? Everytime GPS registers a new location; does it update it? What I want to know is that if it's not latest can it still be closed to latest? As I didn't see an option in android emulator to configure the time period between subsequent updates.
View 1 Replies
View Related
Jun 1, 2010
I was wondering if it's possible to call specific methods defined within the AsynTask class from another class and/or service ?
In my specific case I have a Service playing some sounds, but the sound is selected from a List with available sounds...
When a sounds is selected it is downloaded from my home server, this takes some time (not much, let's say around the 3-4 seconds, the sounds/effects aren't big in size)...
So my problem at the moment is that I have a service to play those sounds, and when I select one I wanted to show a progressdialog... The way (if I understood correctly) is to use an AsyncTask, but the only thing the AsyncTask will do is telling my Service to play a specific sound from my server... So there is no "callback" from the service to the Asynctask...
How can I call a running AsyncTask, which sits in another class, and tell him all work is done and thus he can stop showing the ProgressDialog ? Or am I over-engineering it and there are other ways ?
View 2 Replies
View Related
Aug 13, 2009
I want to hide my application from user so i just want to create service. Can some one tell me how can i create service only with out activity. Can some one tell me can i create only the service in whole project instead of activity. Is it feasible?
View 5 Replies
View Related
Feb 11, 2010
I'd like to know if it's possible to create a Singleton Service throughout an application ? Let's say I'd like to cerate a Service to play some mp3... I'd like it to be a Singleton, we don't want two mp3 tracks playing through each other (well maybe some would want that, but in my case I'm not making a DJ app) :P Also this Service should be somewhat dynamic as in there should be some interface so that I can stop, pauze and play the mp3 file/ stream. Now I have a couple of questions : - is this feasible ? - should I be using a Service or something else ? - how can an interface be set up in between an application and a service so that I can start, stop, pauze stuff ? - can there be something like a Singleton Service?
View 9 Replies
View Related
Sep 3, 2010
How can I create a WCF service for Android client.
View 1 Replies
View Related
Sep 11, 2010
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):
CODE:........
It gives different hash codes even when I am sure that the same function is running twice (downloading):
CODE:............
I am binding a Activity to the service with:
CODE:.......................
And the service can run for minutes until it is completed, therefore the service can be binded to/created by many Activities.
View 1 Replies
View Related
May 26, 2009
I've read some of the earlier posts on this subject, but I've found them confusing.I'm trying to create a Client Application using Android 1.5 that can call a .NET Web Service using SOAP.I understand that the kSOAP2 library can help here and I've imported that into my Project.I need assistance in correctly using the kSOAP2 library to develop the application.
View 2 Replies
View Related
Jul 8, 2010
I am trying to create a Servicefor my application which will negotiate Bluetooth connections and data. I want this service's lifecycle to start and end with the Application, but still be able to have specific Activities listen for events that occur within this service (in addition an Activty should be able to call specific methods of the Service to write data or query connection state).
I started by creating AIDL interfaces for my callbacks and service, but I can't figure out exactly what I'm doing.
How is the best way to go about this? EDIT: To be clear, I do not specifically need (or want) more than one process for my application. Right now I don't have more than one; I'm just using AIDL because it is the only way I know of for a Service to communicate with an Activity.
View 1 Replies
View Related
Aug 12, 2010
I have a Service that creates AsyncTasks for downloading files. In activities, we create Runnables or Threads that we pass to Activity.runOnUiThread(). I can't access that method from a service, so how do I use AsyncTask correctly, (do heavy work without blocking the UI Thread)?
View 1 Replies
View Related
Mar 23, 2010
I want to create a service that runs on Android which can collect all of my location information. Either write the information to a file or send to a server using 3G/wiki network. I was thinking about using a service that runs forever as a daemon. After reading "Diamonds are forever, services are not" by Mark Murphy, I realized that it is not a good idea. However, I need to somehow acquire the moving trajectory information on the Android phone. Without a daemon service running forever, how do I do that ?
View 4 Replies
View Related
Aug 26, 2010
I'm new to the android platform, and I need to create a background service that listens for actions from different applications, the home activity, menu items in different apps, etc. Is it enought to call several event listeners and pass the different home activity events (and events from other activities) to the listeners? If so, what exactly to I pass to my event listener? Is the home activity an object that I can call? What is it and how do I pass it? Otherwise how to I listen for user interaction with variouse elements of a given view/activity? I need the listeners to trigger an activity that occurs before the event they asked for. For example. 1. They press the arrow button on the homescreen. Before it pops up, a picture pops up on the screen.
View 2 Replies
View Related
Jul 19, 2010
Is it possible to create my own backup transport for my own cloud service I offer?
View 8 Replies
View Related
Oct 23, 2010
I'm having a problem while accessing a web service through ksoap2 library, is there any other way to access the web service. I can't use ksoap2 library for my project. Should I create a soap library or any other way.
View 3 Replies
View Related
Feb 25, 2010
Here I update my world to include the canvas size. world.getViewPort().updateViewPortSize(width,height); Is there a better way to do this? Is there a way that I can automatically update my world object without having to manually call it in the setSurfaceSize method but instead call it from My world class? My guess is that I can use some sort of callback, but I don't understand them!
/* Callback invoked when the surface dimensions change. */
public void setSurfaceSize(int width, int height) {
// synchronized to make sure these all change atomically
synchronized (mSurfaceHolder) {
mCanvasWidth = width;
mCanvasHeight = height;
world.getViewPort().updateViewPortSize(width,height); }
View 1 Replies
View Related
Jul 30, 2009
How to create a service that will post messages to an activity periodically using timer?
View 2 Replies
View Related
Oct 13, 2010
If it must implement with AIDL? And please kindly provide an example. There are several solutions, Does anyone know which is better?
View 1 Replies
View Related
Sep 17, 2010
I am doing authentication with a third-party site that's supposed to redirect back to my app with auth token (OAUTH).
I have the callback working properly if I open the 3rd party site in a separate browser process via this.startActivity(new Intent(Intent.ACTION_VIEW, uri));
But, if I embed a WebView component in my layout, and open the url in that, the callback does not work. Webview says "You do not have permission to open myapp://callback?token=...." and quickly refreshes to "Web page not available...temporarily down..."
View 1 Replies
View Related
Aug 17, 2010
We are supposed to make UI actions only from the main UI thread. But it is not clear to me if callbacks like LocationUpdateListener (and other callbacks from sensors) are already in the UI thread or they require special care to access the UI components.
View 2 Replies
View Related
Sep 23, 2010
I just switched over from iPhone to Android and am looking for something similar to where in the iPhone SDK, when a class finishes a certain task, it calls delegate methods in objects set as it's delegates.I don't need too many details. I went through the docs and didn't find anything (the closest I got was "broadcast intents" which seem more like iOS notifications).Even if someone can point me to the correct documentation, it would be great.
View 1 Replies
View Related
Oct 12, 2010
There are a lot of Android SDK APIs where callback handlers are registered. For a concrete example, with MediaPlayer you can set an onCompletionListener callback. Will these callbacks be called from the main (UI) thread? If the answer is "it depends", then I'm looking for some general rules for what callbacks will be called from the main thread versus another thread. The SDK documentation doesn't seem to spell it out. (Maybe I missed it) It seems important to know, because if I'm guaranteed main thread callbacks, then I can skip some thread synchronization on data shared between different places in code. If I'm forced to be pessimistic out of ignorance, then I have to write extra synch block code and worry about deadlocks, data integrity, and reduced performance.
View 4 Replies
View Related
Jul 15, 2010
Is there a way to obtain the time zone from the callbacks received
void onLocationChanged(Location location)
using the time information that can be obtained from the location parameter
long Time = location.getTime();
Or if there is another way please provide info!
View 2 Replies
View Related
Aug 3, 2010
I want to get the size of a view that is in my activity but I am not able to get that information in any of the activity lifecycle callbacks (onCreate, onStart, onResume). I'm assuming this is because the views have not been drawn yet. At what point are views drawn and is there a callback I can put my code so I can get the size of the view?
View 2 Replies
View Related
Nov 16, 2010
I'm new to Java, I'm porting over our Windows Phone 7 library to run on Android. Due to syntax similarities this has been very simple so far. Our library is basically an abstracted http message queue that provides data persistence and integrity on mobile platforms. It only provides asynchronous methods which is a design choice. On WP7 I make use of delegates to call the user supplied callback when an async message has been processed and the servers response received.
To achieve the same thing on Android I've found two ways so far - A simple Java listener interface that contains OnSuccess and OnFailure methods that the user must implement, or using the Android handler class which provides a message queue between threads(http://developer.android.com/reference/android/os/Handler.html).
I've gone with the Handler at this stage as if I'm honest it is the most similar to a C# delegate. It also seems like less work for a user of our library to implement.
Example of some user code to make use of our library:
CODE:.............
Using this the user can create as many different handlers as they'd like, called whatever they'd like, and pass them in as method parameters. Very similar to a delegate...
The reason I'm wondering if I should move to a listener interface is because the more exposure I gain to Java the more it seems that's just how it's done and it's how third parties using our library would expect it to be done.
It's essentially the same process, except each time you wanted to do something different with the server response i.e. You might be fetching different types of data from different endpoints, you're going to have to create a custom class that implements our interface each time, as well as implementing any methods our interface has. Or of course you could have a single monolithic class that all server responses were funneled in to but have fun trying to figure out what to do with each individual response...
View 2 Replies
View Related
Apr 2, 2010
I am developing on a Mac with Eclipse and have the skeleton for an app that implements the standard framework callbacks (onCreate, onDestroy, onPause, etc.). When I set breakpoints in the callbacks the debugger stops and displays a tab that says
"ActivityThread.performLaunchActivity(ActivityThread $ActivityRecord,Intent)line:2477" and in the tab page body there is some red text that says "Source not found" and a button that says
"Edit Source Lookup Path...". I have tried adding several paths via "Edit Source Lookup Path..." but can't see to find the one Eclipse is looking for.
View 1 Replies
View Related
Nov 9, 2010
I wanna create an notification application/service, which should be accessable from other applications similar to android's Notification and NotificationManger. As i m a newbie to android development, i wanna know how to develop an service running in background n how to access it from other applications?
View 2 Replies
View Related
Jul 27, 2010
Since FB refuses to sync with my contacts, I deleted my FB for HTC Sense account and tried to create a new one. All afternoon yesterday and now this morning I got the message: "Service Unavailable at this time."
View 1 Replies
View Related
Aug 1, 2010
I just switched over from iPhone to Android and am looking for something similar to where in the iPhone SDK, when a class finishes a certain task, it calls delegate methods in objects set as it's delegates. I don't need too many details. I went through the docs and didn't find anything (the closest I got was "broadcast intents" which seem more like iOS notifications). Even if someone can point me to the correct documentation, it would be great.
View 37 Replies
View Related
Jun 24, 2009
I have a service running in the background.I have a background thread that gets a reference to the service from the application's main activity. But when the background thread calls a method in the service to display a toast, I get the "Looper not initialized exception".Why,if I have a valid, bound reference to a Service, does this still happen?
View 4 Replies
View Related
Aug 20, 2009
I am getting following message when i try to launch service.Also is there any specific path on file system where we need to place the .apk file which contains my serivce component only.
View 2 Replies
View Related