I am facing a problem with Retrofit and Realm with RxJava:
I have a realm observable using Observable.just(realm.copyFromRealm(realm.where(FooBar.class).findAll())) and an retrofit observable using mFooBarService.getFooBars().
I want to combine those so that first the database (realm) and then the api (retrofit) emits the data. I do this by concating them: Observable.concat(realmObservable, apiObservable)
This works good. I can also stop my api server, everything is working fine because the database has the data. Now the problem: if I turn off networking on my mobile phone (wifi, mobile data) no data is received by the observer. I thought that the observer first receives the database data and then a timeout or connection error? Instead I only get an error.
Thank you in advance!
Edit:
Ok, I try to clarify what I mean.
It looks like this if I have network connection but the server is down:
realmObservable.concat(apiObservable)
-----A---B---C---D---|---ERROR-------->
So I get the data and then an error
But when the server is down it looks like this above too but instead I only get an error and not the data first.
I hope you understand me now.
You are getting onError call from Retrofit and not from Realm. Your design of concatenation of Realm + Retrofit seems fine, what you are missing here is error handling for Retrofit when there is no internet connection. You can verify this by commenting all Realm code, and still receiving Error.
There are 2 ways to fix this,
Check for internet connection availability before making retrofit
call
Add custom error handling in retrofit
Related
I am currently storing my transactions in SqLite DB if there is no internet connection at the moment and when there is internet available i send the pending transactions with the new one made so making it quite a lot of data and a lot of API hits which chokes the device and it becomes unresponsive. So need help with a proper way to sync these transactions to the server. Also these are being sended to a Socket as well as a Server.
I tried using AsyncTask for it but it also causes problems if transactions are above 200. Tried Retrofit for it and to some extent the count exceeded from 200 to almost 350 but the issue and unresponsivness remains.
You should give a try to PriorityJobScheduler lib or WorkManager from JetPack.
When there is no network connection you can queue those request and those request will be send ones network connection is available. (So you dont need to wait until someone made new transaction to send old queued data too)
Also, in your current scenario, rather than sending single request for each transaction, ask your API Guy to accept request in List of object format. So you just need to create list of request body object and send to server
I have an android app with server communication layer, implemented with Retrofit 2. It sends requests with .enqueue method. All API methods works fine, except one. In this case after calling .enqueue nothing happents. And i mean it) No exceptions, no messages in logcat. Just silence. Maybe some1 faced with dimilar situation?
I am creating an app which tracks the network details of the user's device.
Trying to build something very much similar to this
I searched a lot, but did not get the answer, how can I get the endpoint of the server (ip address of the server) to which app is talking. It would be great if I get other data as well.
Thank you.
So basically I figured that out somewhat. Every HTTP communication happens through a socket. So I tried to build something around it. Then I found there is SocketImplFactory which you need to implement. And call its createSocket(). So whenever a HTTP (not HTTPS, HTTPS works little different. Have to take care of handshakes and all) call is made a Socket is created. Which in turn calls createSocketImpl() method of SocketImplFactory() which you just have implemented.
Now, in createSocketImpl() method we have to return object of SocketImpl class. And getInputstream() , getOutputstream() methods will be called internally.
I'm having a big performance problem when using AWS Lambda.
I created some basic lambdas that connect to RDS MySQL database and insert/select/delete data in order to return it to the user.
In my client which is an Android App I'm invoking the lambda using aws-android-sdk-lambda:2.2.17 library.
The mismatch is that in the CloudWatch I'm seeing that the Lambdas are being performed really quick - around 60 ms but in my Android app I'm getting the results only after 8-12 seconds.
Unfortunately all that happen after Lambda finishes its invocation and user gets his response is a black box. The problem might be in the implementation of the AWS SDK but I doubt it.
Note - the internet connection is not the problem and it's not a cold execution problem.
Please advice
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.