BroadcastReceiver how to start a new intention

I implemented a broadcast receiver to “block” my application if the Internet connection is lost. By block, I mean that the application should open "No Internet connection."

this is my recipient 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 possible to run NoInternetConnection.class when noConnectivity == true ??

Thank!

DECISION:

Intent i = new Intent(context, NoInternetConnection.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
+5
source share
1 answer

You just need to call startActivity:

context.startActivity(new Intent(NoInternetConnection.class));

You need to make sure that the "NoInternetConnection" activity is registered in your manifest file:

<activity android:name=".NoInternetConnection"></activity>

What problems do you have?

+3
source

All Articles