This is a problem with slow internet connections. I also came across this before, creating an application that was used to retrieve data from a web server. So, there are four things that can help you in this matter: (1) Check if there is any Internet connection or not:
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni!=null && ni.isAvailable() && ni.isConnected()) { return true; } else { return false; }
If there is no Internet connection, you can inform the user about this by dialogue.
(2) If there is an Internet connection, but it is very slow, you can put some code to wait for a response for a certain time, and then show the dialog to the user to wait or cancel the request.
(3) Another thing that is very useful is to use slides slide_in_left and slide_out_right instead of fade_in and fade_out for transitions between intentions. It helps a lot, the screen goes black very rarely.
try { Intent yourIntent = new Intent(view.getContext(), YourActivity.class); startActivityForResult(yourIntent, 0); overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); } catch(Exception ex) { }
(4) Use AsyncTask to send requests to the Internet.
source share