Screen transition when Wi-Fi connection is disconnected

Asked 2 years ago, Updated 2 years ago, 40 views

When connecting to Wi-Fi on Android Studio, the screen is transitioning, but the loading speed is slow, so I'm having trouble.
"OnResume is ""time"" with Activity at the front, so I'm wondering if the loading speed is slow, but I don't know how to quickly transition the screen as soon as I turn off the Wi-Fi, so please let me know."

Purpose
Transition to error screen when disconnecting Wi-Fi.

Current State
The goal itself has been achieved, but when the Wi-Fi is turned off, the error screen is slow (you have to wait a few seconds after the Wi-Fi is turned off or you have to lie down)

url
as a reference https://kokufu.blogspot.jp/2016/12/android-wi-fi-access-point_3.html

Thank you.

public class WifiConnectionWatcher extensions BroadcastReceiver{

    @ Override
    public void onReceive (Context context, Intent) {
        if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)){
            NetworkInfo info=intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
            switch(info.getState()) {
                case DISCONNECTED:
                    Intent1 = new Intent(context,ErrorActivity.class);
                    int1.setFlags(Int.FLAG_ACTIVITY_CLEAR_TOP |Int.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent1);
                    break;
                case SUSPENDED:
                    break;
                case CONNECTING:
                    Intent2 = new Intent(context,AirportActivity.class);
                    int2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity (intent2);
                    break;
                case CONNECTED:
                    break;
                case DISCONNECTING:
                    break;
                caseUNKNOWN:
                    break;
                default:
                    break;
            }
        }
    }
}

android java

2022-09-30 10:19

1 Answers

If you receive BroadcastIntent and are thinking about implementing the , it is difficult to expect immediate response.
For example, if 100 applications are configured to receive the same type of BroadcastIntent, you do not know when BroadcastIntent will be delivered to your application.
(In other words, the more applications you receive, the slower it will be delivered.On the other hand, it may be faster depending on the state of the terminal.)

If you are looking for responsiveness, it would be better to implement registerNetworkCallback in ConnectivityManager to receive changes directly from system services.

Supplementary
There is no guarantee that you will be notified, but if you want it to work as soon as possible, it might be better to use DISCONNECTING instead of DISCONNECTED.


2022-09-30 10:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.