0

I am making an Android application and have decided to use Azure's DB platform. I find adding entries to different tables very easy, but querying the DB to be almost impossible.

Currently I am trying to follow this model: How to get the result of OnPostExecute() to main activity because AsyncTask is a separate class?

In short, it uses an interface to implement a AsyncTask with my query executing in doInBackground(). My problem with this is that it is many many lines of code to execute a single simple query, AND I will need to be doing multiple unique queries when running my app and creating tens of separate interfaces/classes seems extremely inefficient.

At the end of the day all I want is to get the results from this query in a managable way:

final MobileServiceList<Users> result = mUser.where().field("username").eq(username).execute().get();

However it seems to not execute without being wrapped in a AsyncTask like this:

    new AsyncTask<Users, Void, Users>() {

        @Override
        protected Users doInBackground(Users... params) {
            try {
                final MobileServiceList<Users> result = mUser.where().field("username").eq(username).execute().get();

                if(result.size() > 0) {
                    System.out.println("something in list");
                    return result.get(0);
                }

            } catch (Exception exception) {
                exception.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Users result) {
            System.out.println("in post");
            if(username.equals((result.username)) && password.equals(result.password)) {
                System.out.println("found user");

            }
        }
    }.execute();

Is there any easy way to get around this? All I want is a result from a simple query, I don't understand how this is so hard..

Thanks!

Community
  • 1
  • 1
rmw
  • 119
  • 2
  • 10

1 Answers1

0

Unfortunately, there is not any simple way to get around this, please refer to AsyncTask reference to know it for helping Android UI thread to get result asynchronously.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43