0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a million. When I brought up the word service at work my boss told me a service is generally another process. But he doesn't program android himself. I should still have looked into it. Thanks. I think I will be able to go with this. For the queue, is ther eany special kind of object to use? or will a List/Array List be enough?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.