problem with Synchronous call

Hi

I make a synchronous call. But app crash when called

BackendlessCollection<Events> result = Backendless.Persistence.of(Events.class).find(dataQuery);

the code

StringBuilder whereClause = new StringBuilder();
whereClause.append("startTime>='").append(newMonth-1).append("' and startTime<='").append(newMonth+1).append("'");
BackendlessDataQuery dataQuery = new BackendlessDataQuery();
dataQuery.setWhereClause(whereClause.toString());
BackendlessCollection&lt;Events&gt; result = Backendless.Persistence.of(Events.class).find(dataQuery);

When I call Asynchronous call it is work, but i need synchronous

Hello, Amangeldi!

I’ve tried to reproduce this issue, but I couldn’t. Please, tell me, are you trying to run this code from android device?

Alex Navara

Hi

Yes in android device

Hello!

The problem is that synchronous calls are forbidden by Dalvik when running on device - that’s why you receive error. Use only asynchronous and it would work fine.

best regards,
Alex Navara

Another workaround is to use AsyncTask: http://stackoverflow.com/a/6343299/1813669

Thank you

And what is the solution for this? I also want to make a sync call but I cant, only with async is working. What do I need to do in order to work with sync calls?

Thank you in advance.

If you create a new thread, you will be able to make sync calls in it. If you make a sync call in the UI thread, you will get an exception for the reason that network communication is not allowed on the main UI thread.

Regards,
Mark

Thank you. I didnt know that. Im starting to develop on Android so your comment was very important. Thank you again.