i need to make a timer service and bind it to an activity... i cant do it...
can someone share an example of such a thing or a tutorial...
ive already gone through
http://developer.android.com/resources/samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChatService.html
and the adnroid developer documention guide
please help
:/
By quickly looking over the BluetoothChatService code you mention, I've seen that the communication between the activity and the service goes through the Android Handlers.
Try to take a look on the developer documentation on how to use them. Here are also some quite good resources:
http://developer.android.com/reference/android/os/Handler.html
http://www.tutorialforandroid.com/2009/01/using-handler-in-android.html
Related
I'm currently trying to learn how to write custom services and have them start up at boot, all in the Android Source code.
Could anyone point me to the right references (books, online articles, etc) that discuss this specific topic and as well as understanding AOSP/Android operating system in general?
To learn how to write a custom Service you can look at the docs here.
You'll want to learn about Activities and their Lifecycle in the docs here
And you'll want to learn about the Application fundamentals in the docs here
Once you have an idea of how everything works fundamentally, there are tons of tutorials on the internet that will show you how to code specific things. A simple Google search will find you all of that.
Hope this helps!
i'm beginning to learn android, i meet a problem in my project,
in my application,i create a background thread which get data from remote server by UDP,
in this thread ,i will parse the data and distribute the message to different activity to process, so i don't know weather is there a mechanism to handle this problem.
thanks for your answer
You should take a look at this article about painless threading in android, and pick a solution that best fits for you.
If you retrieve data from the server repeatedly, maybe you should go with a Service - Handler solution, but AsyncTask seams to be the easiest for me.
I would recommend you to go through the dev guide as suggested by #UBM. Also, if you are looking for different threading constructs and communication, I would strongly recommend you to look at a series of articles on Android threading constructs starting with this article.
I am searching for a solution to update the UI from a service.
The best solution I found is this one:
subclass Application and let in-app
communication go through this class
As suggested here More efficient way of updating UI from Service than intents?.
Unfortunately I am new to Android and Java programming, so I do not really understand how this works.
It would help me very much, if someone could create a working example project from the given code snippets in the solution. An app that starts a service, increases a counter and displays the counter in textview would be a good and simple example. I think I will understand this much better than a therotical solution.
Here is an answer to a similar question where there is a full example. If you are just doing some basic background task, an AsyncTask may be a better solution though.
Is there a good sample application or tutorial for creating android Service that run in the background?
The Android API Demos include a Remote Service sample. I think we used it as the starting point for our background service. There is also example code right in the documentation for the Service class.
Well, I don't know any apart from my own application. But that is real applications with all the extra code that comes with it and not sample as such.
If you still want to have a go you I suggest you look for Service_Intend and Service_Connection in Calculator_Activity.java and for Calculator_Thread and Binder in Calculator_Service.java. That should give you some idea.
i have a question. I'm developing an Android Application. Actually, i have a thread in background that makes request to an external API in order to get data when the users clicks in different parts of the app.
My doubt is if this "thread" would be better if i implemented it as a service instead of a Runnable class.
Thanks
The point of a service is that it can run while your app is not resident. If you only want the service to run while your app is open then a thread is the probably the best way to do it.
As i learned some days ago, using AsyncTasks is the preferred, painless way in android to do background tasks. Have a look here to get a good tutorial.
http://android-developers.blogspot.com/2009/05/painless-threading.html
bye
If your information can be used by any other application you could use a service or as they are called in Android, a Content Provider. This way you make the information available to all the applications on the phone. This is a great way of encouraging other developers to build their applications with the info that you've provided. This is just something that you should consider, if it's something strictly related to you're application you can go on with the thread just as CaseyB stated.