If it takes a long time to load, it asks for the closing force, how to solve it?

Almost all the actions in my application should interact with the web server to receive data, and then load the Activity screens. Therefore, at any time, if the Internet is slow, it takes a lot of time, and after 12-15 seconds it says: "Unable to load ForceClose / Wait." How do applications avoid this? What solution do they follow when the actions of 1st 3-4 work fine (when the network is good), then some activity takes a lot of time (due to poor Internet / if the Internet is gone)

+1
source share
3 answers

Optimizing your code, secondly, work on the network / Internet is performed in a separate thread (for example, AsynTask).

Link: http://developer.android.com/reference/android/os/AsyncTask.html

This will not block your user interface.

Hope this help

+4
source

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.

+1
source

You can check if there is an existing Internet or data connection before making a call. You must also specify a specific amount of time to try to download the file, then display an error message or try again as desired.

0
source

All Articles