开发者

What is the good practice on android app development integrated with web services?

I have developed android apps, and have a web server application which serves REST style JSON, to the apps.

My apps are strongly dependent on that web services but as traffic gets higher, users' complaint started, as force close problems. I am not sure but maybe my server (AWS small ins开发者_如何学编程tance) may not answer all requests correctly or in time.

I am planning to retry the web request when a problem on getting json response arise instead giving the error/net-connection alert.

I guess there are many developers who integrates apps with web services, so what is the good practice on handling network problems?

Or is the frequency of such network problems acceptable?

I take about 10-20 problem per day. I have about 200.000+ web requests per day, for a AWS small instance (1.7 RAM), dedicated to server Tomcat. I analyze the logs there is no clue, no error log. Also the errors are spreaded.


You need to start with analyzing the problem, and determine the root cause or root causes of your issues. You always need to take into account that

  • a network connection might drop
  • a users switches from 3G / WiFi
  • the android devices "thinks" it's connected while in fact it's not

Also, be very sceptical when using the Android ConnectivityManager / NetworkInfo. Only trust it when it states that it is not connected. If it is connected, check it yourself (as sometimes, user is on a hotspot and the only connectivity he has is with a login page).

The application needs to handle all these scenarios properly. The way it's presented to the user depends on the use-case (do you want the user to be informed of the error, do you silently ignore it and just retry, ....)

In terms of retrying webservice connections, there are several ways to implement this :

  • exponential backoff
  • periodic rescheduling
  • event-driven triggering
  • retry-after moratorium intervals

You need to start by putting sufficient logging both on the client (Android) and on the server (AWS) so that you can analyze the issues and draw the proper conclusions.


I think the answer to your problem lies in the design of your android app.

You need to take into consideration the worst case scenario and redesign your application to take that into account and recover. Dealing with the chaos monkey - jeff atwood.

Personally I never allow an android app to be in a state where it needs to force close. For any or all network connection I assume that the connection is down, lossy, not all data can be retreived and (finally) up and working correctly.

That way my app will degenerate gracefully. If it needs web access it'll make an attempt in a background thread allowing the user to continue using the app, it will cache previous requests and will retry until it gets a connection or gives a nice toast to the end user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜