@Override
        public void run() {
          if (broadcastSendJob == null) return;

          discoverIsRunning = true;

          udpSending.addJob(broadcastSendJob);

          NetpowerctrlApplication.getMainThreadHandler().postDelayed(this, 1500);
        }
  @Override
  public void onResume() {
    super.onResume();
    udpSending = new UDPSending(true);
    udpSending.start("NeighbourUDPSendThread");
    udpReceiving = new NeighbourDiscoverReceiving(this);
    udpReceiving.start();
    advanceTimeRunnable.run();
    // Reset icon size cache, will be set on next sending
    NeighbourDiscoverSending.icon_size_cache = -1;
    checkNetworkState();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    //noinspection ConstantConditions
    getActivity().registerReceiver(wifiChanged, intentFilter);
  }
  @Override
  public void onPause() {
    super.onPause();
    if (udpSending != null) {
      udpSending.interrupt();
      udpSending = null;
    }
    if (udpReceiving != null) {
      if (udpReceiving.isAlive()) udpReceiving.interrupt();
      udpReceiving = null;
    }

    NetpowerctrlApplication.getMainThreadHandler().removeCallbacks(advanceTimeRunnable);
    NetpowerctrlApplication.getMainThreadHandler().removeCallbacks(sendDiscoverMessageRunnable);

    // Stop tcp receiver
    NeighbourDataReceiveService.stop();

    try {
      getActivity().unregisterReceiver(wifiChanged);
    } catch (IllegalArgumentException ignored) {
    }
    wifiChanged = null;
  }