0

in my app i am trying 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.........

Siva K
  • 4,968
  • 14
  • 82
  • 161

2 Answers2

1

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
  • 40,203
  • 9
  • 86
  • 108
0

@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.

Adeel Pervaiz
  • 1,336
  • 10
  • 11