0

I'm developing an app. Application restarts when wifi network is switched from netwok-1 to network-2. Problem is that I don't know to detect changing in wifi network. Any help or suggestion would be appreciated.

Sarweshkumar C R
  • 543
  • 1
  • 8
  • 19

1 Answers1

0

In general you don't have to take care of the which wifi network is connected, ConnectivityManager will do it on your behalf.

ConnectivityManager cm =
     (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
                      activeNetwork.isConnectedOrConnecting();

Now if your app/device(s) changes network state, then you need to monitor the connectivity_change using some broadcast.

<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>

It'll help you to broadcast only when you've previously suspended updates or downloads in order to resume them.

This tutorial will help you.

Pradip
  • 3,189
  • 3
  • 22
  • 27