I've been trying to make a widget to my music app.
The app has a service that handles the mediaplayer so that i can "minimize" the app and yet continue listening to music.
I know that i need to update the widget from the service, but all the examples i've found, wants me to start a new service on each update, and that's not what i want.
Any help is appreciated!
Thanks in advance
You can do it without the service too. The service is recommended because if your updation takes too much time, android may close it and give Application Not Responding (ANR) error message. These are the cases like when you send a web-service request. Otherwise, you can use your custom AppWidgetProvider to update your widget (without making a service), using RemoteViews(the same way you do in the service). For more on how to do that refer this
Related
I have to write an app that is supposed to send user location to server.
I have class that is listening events from Android and it sends data to server bia webservice.
Do I have to put that in some service, or I can just put it into my MainActivity class code?
Im asking, because Android is still weird for me. It pauses activities and I don't know if this will work "from the background" or not.
Of course I want to update location when application is in foreground and background too.
Yes you will have to use a Service to send data in the background as well as foreground.
You can use android Service or Background Service,
based on your requirements I would suggest using the Background Service.
Here are the links for both:
Service:
http://developer.android.com/guide/components/services.html
Background Service:
https://developer.android.com/training/run-background-service/create-service.html
if you want the location irrespective of the fact that the application is open or not then you need to have a service which will keep on posting your location to the server.
Here's how you can do it ...
Read this answer
Note :
Activities can't do what you want to achieve as they exist till the user exits them (by pressing the back button, killing them or clearing the stack[Need not think of it for now if a newbie]).
There is a good article on android.com website
https://developer.android.com/training/location/receive-location-updates.html
I am developing an Android Application that is supposed to auto-upload images as soon as they appear in the Media Store. For this, I have implemented a Content Observer which is registered inside a Foreground Service to constantly monitor the change in Media Store and there is an upload Service which is triggered onChange() of Content Observer.
I am considering not using the Foreground Service as it wastes a lot of resources, what would be the best way to implement this?
P.S. - I have considered using scheduled Service too, but that wouldn't be of that help.
Thank You.
In my Application I have several Activities and a Java class with a thread. This thread continuously receives and sends messages to the web server. The Application is working fine in testing but I am worried that it may not when being used in actual phones. I am afraid that my background thread which continuously interacts with the Server might be killed by Android, while the app is in background.
Do I really need to make my threaded client class a service ? I want to start it when user signs in and stop it when the user logs off from the system.
If I need to do it please suggest some easy tutorial for it.
See these links..
http://www.vogella.com/articles/AndroidServices/article.html
Example: Communication between Activity and Service using Messaging
http://androidtrainningcenter.blogspot.in/2012/04/simple-example-of-service-in-android.html
As far as i think you better use TimerTask along with Timer along with any normal class or service will suffice your objective.
I need an advice for my latest app. It will show the user the latest subtitles released, and it will give him a notification in case new subtitles of his favourite series have been released; what should I use to achieve this?
I was thinking to create and run a service which will include a
timer.scheduleAtFixedRate(new TimerTask() {...
but at the same time I really don't know how to make it interact with my app (if the app is opened I don't need any notification but I need to update the GUI).
I could use a thread but I'd like it to run it even after the main activity has been killed...
or I could use a AsyncTask so it would be easier to deal with the Application GUI.
Which solution should I use? I was thinking I should simply use a service (the first solution), but I'm not too sure about it, and furthermore I don't know if there is any way to make a service communicate with an activity periodically...
Thanks for your help.
A service communicating with an activity is called bound service, that's what you should use IMO.
However, you say that when the activity dies, the service should keep running. But if the service is bound to your activity and the activity is dies, the service dies too.
I suggest you to read here about it.
Check and see if you can bind a service to an activity, and when it dies, unbind and let the service continue to run independently.
If you can't, the activity could unbind itself, then start the service independently (with startService rather than bindService).
if you are showing notifications, why not use C2DM messages for communicating with the app. The only thing would be that there would be popups shown to the user even if your app is not running. No need to use threads/services.
I need some help or suggestions regarding Background services.
Well I want to achieve this. I have an application with Some Views that application also has a Background Service that always keeps on running.
In my views there is a Button whenever I press that button, that button passes some files to the Background Service and my Background service upload that file onto some server.
I am done with the uploading process. Now I want to know that how can I make a Background Service that always keeps on running and on my tapping of the button it sends a file to the Service.
I am new in Background service implementation.
Please guide Friends with some tutorials, suggestions or guidelines.
Thanks a bunch
You've probably already read some of the Android Service documentation, but I suggest studying it further and looking at the Local Service Sample if you have not done so already:
http://developer.android.com/reference/android/app/Service.html
It sounds like you have already got your Service up and running, and I think the actual problem you are trying to solve now is how to communicate data from your Activity to your Service. When your Activity is bound with a Service that's part of the same application, that service is in the same process and runs on the same main UI thread, so once you get the IBinder object from the Service after binding with it, you can simply directly call the functions in that Service from your Activity. Similarly, you can pass your Service a handler object from your Activity so that the service can send messages or post Runnables to your Activity. Communication with a local Service is therefore quite simple.
So if you take a look at the Local Service Sample in the link above, you will see a section in the code where we get a reference to the Service once binding has completed:
mBoundService = ((LocalService.LocalBinder)service).getService();
After that point, it's possible to directly call methods on that Service that's in the same application. For example, you could have a method called sendFile in your Service. In your Activity, you might do something like:
mBoundService.sendFile( myStuffObject );
There are quite a number of questions on Stack Overflow regarding communicating between an Activity and a Service, and I think you'd find it beneficial to search and read these.
A standard Android service will do just fine in this case.
It will continue running in the background untill its work is finished or until you ask it to stop.
There is a topic on the android dev site explaining services in detail.
you should go for android Service that is used for Background operation . Inside the service your have use TimerTask which will be checking the Queue for every x sec and when any items present in the Queue it will pull the item and upload it to the server.
here is the link for Android Service..
http://developer.android.com/reference/android/app/Service.html
Link fro Queue.http://developer.android.com/reference/java/util/Queue.html