0

I have Parse method "inBackground()" that does not work, for example:

  ParseUser.logInInBackground(emailAdd, passwordAd, new LogInCallback()
            {
                public void done(ParseUser user, ParseException e)
                {
                    if (user != null)
                    {
                      finish();
                      Log.d("message","ok");
                    }
                    else
                    {
                     Log.d("message","fail");
                    }
                }
            });

but if i do:

user = ParseUser.login(emailAdd,passwordAd);

in Asynctask, it works.

My question is: is better to do this queries in Asynctask or an IntentService? What happens if the user press "home" or "back" button?

Thank you

ste9206
  • 1,822
  • 4
  • 31
  • 47
  • what is the ParseException in logInInBackground? – ChunTingLin May 14 '16 at 09:35
  • Possible duplicate of [android design considerations: AsyncTask vs Service (IntentService?)](http://stackoverflow.com/questions/3817272/android-design-considerations-asynctask-vs-service-intentservice) – Vucko May 14 '16 at 09:42

1 Answers1

1

AsyncTasks are used for background work that will not take up too much time, usually the UI is waiting on something from the background so you don't want to hold it up. So for example, getting a list of countries to bind a list adapter too or something of that nature. IntentService is used more so for longer running processes. You can run an IntentService for something like a GPS Service that constantly listens for GPS updates.

AsyncTasks are tied to the context, so if you press back or do anything that disrupts the context you are in it will kill that task and will not restart on it's own. You will need to need to do that yourself, and you will lose the data you were trying to retrieve if it happens at a bad time. So it's important to manage the lifecycle properly.

I'd recommend taking a look at RxJava. A learning curve for sure, but way cleaner.

As to why the inBackground is not working, I'd need to see how the networking is done and how this is tied in to your activity lifecycle. Hopefully this helped!

paul_hundal
  • 371
  • 2
  • 9