It seems to work fine but after sometime all calls to saveEventually and saveInBackground are not saving data to parse (there is no callback and there is no error message as well). It seems it is silently discarded. When this happens, we are still able to fetch data from Parse i.e. all read queries work. We are using local storage. The updates start working again once we clear the app data. What could be causing this? How can we debug the requests that are silently discarded?
You are using a synchronous function saveInBackground. If you want to have callbacks, you need to call the asynchronous version saveInBackgroundWithBlock instead.
Please read the Parse documentation carefully before posting a question here.
Related
I have two ways to sync between local database to server.
AsyncTask
WorkManager
Here is the flow of syncronization:
AsyncTask/WorkManager fetch data from local DB to upload to server --> if (response.status == "success") then remove the data
But the problem is, AsyncTask and WorkManager possible to run almost in the same time and fetching the exact same data each other that caused double data in server.
I need to use both since WorkManager is buggy and can't be trusted and I cant really rely on Asynctask alone as well.
Is there any way to avoid this double data?
You should try to accomplish one task by one mechanism only - otherwise you will always run into concurrency issues.
What's buggy about `Workmanager? Maybe you have it set up incorrectly. There are good talks from the Google IO in Workmanager,
If you really encounter a bug, file an issue.
Furthermore there should be no need to use AsyncTask anymore, please try to avoid it completely as it really is very error prone. There are many better things for asynchrounous work (workmanager, coroutinen, rxjava, ...)
I'm trying to determine whether or not I download data in my android application. I can do this by making the method return true when it does download data, but the listener doesn't seem to be invoked until all other code is finished running (meaning it waits until a pause in your code). So I'm wondering if there is a way to sort of "forcibly" invoke these listeners? Perhaps by creating the listener in a different thread? Would this work or would it be a waste of time? I've already tried to sleep on the main thread for a few seconds, but that doesn't seem to do it either. If it wouldn't work, could you explain when exactly these listeners are invoked? Thanks in advance.
To add onto my question, I am NOT using the realtime database. I understand how realtime triggers work, but I am using the Firestore, so I am only getting data once, not getting realtime updates :)
As you have already noticed with the API calls that deal with reading and writing data are fully asynchronous. This means that the call always returns immediately, without blocking the code to wait for a result. The results come some time later, whenever they’re ready, since it may take some time for this. Depending on your connection speed and the state, it may take from a few hundred milliseconds to a few seconds before that data is available. So Firebase, already is using another thread (other than the main thread) to get the work done.
Calling a synchronous function on your app’s main thread could freeze the app indefinitely, which is a terrible UX. On Android, it could also soft-crash with an Application Not Responding (ANR) dialog.
Doug Stevenson, has explained in his post everything that you need to know about Fireabse asynchronous behaviour and what you need to do/avoid when dealing with Firebase.
In our Android app, we are using saveEventually() and saveInBackground() of parse sdk (version 1.8.0).
It seems to work fine mostly but sometimes all calls to saveEventually and saveInBackground fail with the callback not getting called.
when this happens, we are still able to fetch data from Parse i.e. all read queries work.
We are using local storage. The updates start working again once we clear the app data.
What could be causing this?
It's because Parse.enableLocalDatabse() is on. I had this one before - it's hard to get to this point (it took me couple of days to figure it out). So get rid of this one in Your Application class and it should work.
Oh, and get latest version 1.10.3
I'm writing a chat application on Android using the Parse SDK (1.5.1) in which i use obj.saveInBackground(SaveCallback) to create a new chat message on the cloud. The problem is that sometimes the SaveCallback never get called (I put a log inside the callback and that log never be printed out).
This usually occurs when i continuously send out about 20-30 chat messages, for each message, i use saveInBackground to create it, but the callback just be called for the first messages (for example, it was ok to create message 1 to 30, but for message 30-40, the callbacks were not called and they couldn't be created).
It seems that when the problem occurs, all the "ParseRequest.NETWORK_EXECUTOR-thread-xx" threads are in the Wait status (maybe they are waiting for results sent back from server?).
Please take a look at the application's threads snapshot when this problem occurs.
Is there anyone encountered a similar problem before? Could you please give me advices how to deal with it?
Thanks!
I faced similar problem in case of files, so I used recursion function. may be you have to call recursion method of saving messages until all messages are saved to parse...
I'm wondering if an Android Loader (more specifically AsyncTaskLoader) is the correct job for asynchronously submitting data to a web service.
The way I see it, most of the examples deal with grabbing data and displaying it to a user. For such operations things like having it "accidentally" hit the URL endpoint twice, or caching data is the norm.
However, when we're dealing with submitting data we want a way to absolutely make sure that:
the data is only submitted once
the submit operation is done anew each time we call it
we can pass a result back that will notify the user that the action was successful (or failed)
So, with that being said, how would I go about using the Loader pattern to send data in an asynchronous fashion? Are there any examples that exist for this type of use-case? Or is a Loader not the right thing, and I should be using something else altogether?
I don't agree with Nikolay on this one (I know how it sounds with my reputation against his;)). I use Loader (AsyncTaskLoader) to write data as well. More specifically I have an AsyncTaskLoader which checks for data on-line and then writes it to local database. It works like a charm and doesn't have AsyncTask drawbacks when it comes to persistence and leaking problems.
And it has the thing which you need (probably needed) - it doesn't run twice e.g. on configuration change, because it reconnects to the existing loader.
What you need to do is to put your submitting code in the loadInBackground() method and you're home.
You are probably looking for AsyncTask. The loader caches data internally and returns it to the app to be displayed by the app, it is not really designed to submit data. Why do you think you need to use a Loader for this?