Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronous service calls in Android

I'm working on application whose main responsibility is to contact remote server and display the data provided.

Service is Soap based. For that I use ksoap library, but let's cut to the case.

I've been "calling service" with the use of asynchronous tasks. Everything seemed to go well, but...

Service is sequential, and tends to 'lose' my requests, so I don't get proper results.

So I decided to take a synchronous approach to resolve the issue, but this way I have to provide additional loading buttons/bars etc.

The performance is terrible in this way. What is the best way to handle such case ? What kind of synchronisation can I use so there won't be any race between the requests ?

How can I make use of Android Services ? How are those better?

Thank you in advance for answers.

like image 438
Olek Avatar asked Feb 09 '12 20:02

Olek


1 Answers

You can actually call the AsyncTask in a sync way:

class MyTask extends AsyncTask<Void,Void,String>
{...}

MyTask x = new MyTask();
String result = x.execute().get();

See the docs page for AsyncTask

like image 68
Heiko Rupp Avatar answered Oct 29 '22 00:10

Heiko Rupp