how to save request and resend in android app
in my app i am tryin开发者_JAVA技巧g to send some data to a network. but the app is getting slow or gets crashed when the network is not available.
how to save the request for later and resend it once the phone has network coverage again?
how to do this.........
Upon transfer failure, you can use public final boolean postDelayed(Runnable r, long delayMillis)
to try again in a set time. You will need to set up a Runnable
class and send the data overriding run() method.
http://developer.android.com/reference/android/os/Handler.html
http://developer.android.com/reference/java/lang/Runnable.html
@Aleadam is right, you should post your data later once your internet is connected, however you can check your intent connection by this method.
public boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
but this method will require to import some android libraries here are these
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
I hope this will help.
精彩评论