Skip to content

Commit 84c3905

Browse files
author
Geremy Cohen
committed
Update android/README.md
Reflecting simpler, general case DAR logic in Android.
1 parent 7cb9056 commit 84c3905

1 file changed

Lines changed: 12 additions & 29 deletions

File tree

‎android/README.md‎

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,19 @@ The **onReceive()** method is where it checks for certain (or any) network chang
3434
calls **disconnectAndResubscribe()** as needed.
3535

3636
```java
37+
@Override
38+
protected void onCreate(Bundle savedInstanceState) {
3739

38-
public boolean haveInternet(Context ctx) {
39-
NetworkInfo info = (NetworkInfo) ((ConnectivityManager) ctx
40-
.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
41-
42-
return ( info != null && info.isConnected());
43-
}
44-
45-
protected void onCreate(Bundle savedInstanceState) {
46-
...
47-
this.registerReceiver(new BroadcastReceiver() {
48-
49-
@Override
50-
public void onReceive(Context arg0, Intent intent) {
51-
boolean haveInternet = haveInternet(arg0);
52-
53-
if ( haveInternet != networkConnected) {
54-
Log.d("Receiver 1", "Net state changed from " +
55-
networkConnected + " to " + haveInternet);
56-
}
57-
58-
if (haveInternet && !networkConnected ) {
59-
pubnub.disconnectAndResubscribe();
60-
}
61-
62-
networkConnected = haveInternet;
63-
}
64-
}, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION ));
65-
....
66-
}
40+
super.onCreate(savedInstanceState);
41+
setContentView(R.layout.activity_main);
42+
43+
this.registerReceiver(new BroadcastReceiver() {
44+
@Override
45+
public void onReceive(Context arg0, Intent intent) {
46+
pubnub.disconnectAndResubscribe();
47+
}
48+
49+
}, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION ));
6750
```
6851

6952
This logic has been purposely left out of the core and documented in the example application, so that if you wish to

0 commit comments

Comments
 (0)