Android queue's and threads

I am in the middle of developing an android application and I have stumbled across something that I don't really know the best way to solve.

What I wwant to achieve is, when a user logs into the application, I want to start a thread if the device is connected to a network(what kind of network doesn't matter)

The thread should perform an action every 10 minutes.

What this thread needs to do is, loop trough a list, a queue to be more exact. This queue will have objects, and based on the objects in the queue when there is a connection available, execute.

The queue will be filled trough the flow of the application. For example filling in a questionary.

The answers need to be synched to the server. Every question can include pictures takebn from the camera etc, so I want to save certain data as an object, put them in a queue, and have a thread handle the http requests. This way the UI won't be blocked. It's of great importance to sync whenever possible.

What I want to avoid is having another process run aside from my own APP. That's why I haven't used a service. Or do I missunderstand the concept of services as a whole?

Are there specific queue objects or lists? I want to loop trough the queue list that can be filled at anytime while the program is alive, with a thread.sleep like method when the list is completely empty.

Please leave me hints and tips on what way to go with this.

Answers


A service isn't it's own process... from the Documentation: "A Service is not a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of."

A service really is the best choice for what you're talking about. You spawn your own thread in the service that then does the following: check your queue for objects and send any to the server (since you're already not on the UI thread, you can do this without spawning yet another thread if you want). If the queue is empty, use a Timer to schedule another invocation of your upload method.


Need Your Help

JavaScript to Redirect Users To Page Depending On The Address They Are Accessing The Web Stie With

javascript php scripting redirect

First i would like to start off saying that i am sorry if someone else has posted something about this. And Secondly i am new to html and JavaScript so i need a step by step explanation. I am worki...

Is there any real use case for function's reference qualifiers?

c++ c++11 c++14 ref-qualifier

Recently I learned about function's reference qualifiers, e.g.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.