Retrofit ignores some requests - android

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?

Related

Can we chain multiple API calls or keep track of multiple calls being made at once?

I have 21 API calls that need to be made once the app gets to the splash screen. What my app does is as follows:
a> Make API call using retrofit's enqueue method.
b> once the response is available(call success) it stores data to local database using greendao. Inside app it only uses data from greendao databases. What I need is to keep track of the api call whether it failed or not. If failed retry. Also if there is a way to chain the requests can anyone mention them? I looked into rxjava which allows chaining upto 2 or 3 apis (as far as I know). Any help is much appreciated.
You can create IntentService which will run call.execute() code one by one.
This way you will call synchronous call to all apis.
Once all request completes send broadcast to activity or communicate with activity through other mechanism.

Android : Getting server end point to which app is making API calls. (Network / API call tracking)

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.

Disabling networking stops emitting data from realm

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

loopj multiple async requests not returning in signed APK

I have an app that requires a lot of async requests, for which I am using the loopj asynchttpclient library.
After login to a service, many requests get made, someone loading 5-10 images at one time, and a couple JSON requests, all made around the same time. I never had an issue in all of my debug testing over the last several months. But after building a signed APK and installing, when multiple requests get ran simultaneously (in the above description) - the requests stop returning anything. None of the call backs are called. The server is receiving the requests and returning, but the async http callbacks never get called.
I have read that if all the callbacks are not implemented its possible they won't call, but I have implemented them all including the deprecated ones and still no luck.
Any reason why this would happen? I am kind of late in the game and am trying to avoid having to switch to an entirely different networking library.
Cheers

Android's ContentResolver.isSyncActive returns false before the actual sync is over

I am triggering a sync with a REST service using SwipeRefreshLayout's onRefresh method by calling ContentResolver.requestSync, which launches my Syncadapter.
The Syncadapter then uses Volley's Request to communicate with the server.
To detect the end of the sync operation and close the activity indicator I use ContentResolver.isSyncActive inside SyncStatusObserver of the Fragment from which I initiated the sync.
The problem is that the ContentResolver.isSyncActive returns false before the actual sync with the server is over, causing the activity indicator to disappear almost immediately.
Am I correct assuming that the asynchronous nature of Volley's Request causes the SyncAdapter's onPerformSync to return immediately which, in turn, makes the ContentResolver think that the sync is over?
If yes, what is the correct/recommended solution here? I can come up with workarounds, but wanted to make sure I am not missing something obvious.
I have looked through many examples including iosched, swiperefresh, basicsyncadapter etc., but they all seem to "hold" the onPerformSync method until everything is over.
Thank you
You should make the requests act synchronously inside the onPerformSync method. I use Retrofit for calls with backends but I think Volley should also provide the synchronous functionality.

Categories

Resources