I implemented a broadcast receiver to "block" my app if the internet connection is lost. By block I mean that the app has to open a "No internet connection" activity.
this is my receiver code:
public class ConnectivityReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
Log.d("** Debug **","noConnectivity " + noConnectivity);
if(noConnectivity){
//SHOW NO INTERNET CONNECTION ACTIVITY
}
}
}
Is it possibile to start NoInternetConnection.class when noConnectivity == true??
Thanks!
SOLUTION:
Intent i = new Intent(context, NoInternetConnection.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);