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.
Related
I' am looking for solution to running custom process indefinetly in background, even if user quit from application. It would fetching data from the server and generate local notification. I' am working with Nativescript/Angular and I heard about Workers but as far as I know, they can't keep the process if the app is not in foreground. It would be greatful if the solution will be suitable for IOS and Android. Have you any ideas to do this? Thanks in advance for your involvement
iOS can not run something on background continuously. It's the OS which decides when your background execution can run. Refer BackgroundExecution docs for more info and samples.
On Android you are free to run it continuously at least until the user blocks it on his choice, sample implementation can be found here.
I want to make an android application which will display an external message (For example: some quotes, proverbs etc) daily.
The message should be retrieved from some place other than the client device and I would like to configure the messages from back end
These messages should also change everyday.
How should the back end be and how can the android application retrieve the configured message ?
Do I need a server at the back end for the same or can avail some cloud services for the same ?
What is the best approach to do?
If you want to avoid having to set up and manage a server on the backend yourself you can take a look at a 'backend as a service' offering.
Two example candidates are:
https://parse.com
http://aws.amazon.com/lambda/
Both Parse and Amazon provide SDK's to allow you interact with the backend from your Android app.
You will likely want to study this a little to decide if you want this type of solution or to build your own server as Brian suggests - I think there are pros and cons to each approach and you'll have to choose which is best for your case.
Yes, you will need a server. You can start building the server software on the same machine as your Android emulator and create them in parallel. You'll need to choose a language and most likely a web server framework that suits your thought process and style.
If you want to use REST, for instance, google some for "best REST server framework". You will get hundreds of answers that don't mean much, but look at the communities that surround the frameworks that come back. Look at the user lists and how many questions about it exist on this site. That will give you a better idea of whether you can ask questions and get answers when they arise. You are making an investment by learning a framework, spend a little time deciding which one you are going to use, possibly by trying a few of them for a very simple site that returns the kind of data you are looking for.
Other than that, you really need to ask specific questions once you've chosen a language and a framework. Hope that 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.
how can i get all the system notifications that are shown now?i want to write a programe that can intercept the notifications that other apps notified.
You cannot interfere with another appliactions notifications so it will not be possible to write such application.
This thread from the Android Beginners Google group answers the question with a solid "No." Quoting a user from the thread:
No, sorry. Intercepting notifications,
in particular, would be quite the
security loophole. In general, on
Android, one application cannot see or
mess with another application's
stuff. So, while your desired features
would be interesting for the OS
itself, they aren't going to be very
practical to implement in an
application written to the SDK.
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.