0

I have a helper class to handle Network Service Discovery, where I declare the NsdManager.ResolveListener, once it resolves a service I want to update the Activity list view.

My Activity onStart

@Override
protected void onStart() {
    mNsdHelper = new NsdHelper(this);
    mNsdHelper.initializeNsd();
    super.onStart();
}

I want to update back the activity once the service is resolved:

    mResolveListener = new NsdManager.ResolveListener() {
        @Override
        public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
            Log.e(TAG, "Resolve failed" + errorCode);
        }
        @Override
        public void onServiceResolved(NsdServiceInfo serviceInfo) {
            Log.e(TAG, "Resolve Succeeded. " + serviceInfo);
            mService = serviceInfo;
        }
    };

How do I do that?

Doron Sinai
  • 1,166
  • 3
  • 12
  • 28
  • I'd suggest using a 3rd party library called EventBus. It's good for this kind of stuff. Google it, they have good docs to get you started easily. – Vucko Jul 19 '16 at 19:21
  • Why would he need to use EventBus? He's not bridging Service/Activity or BroadcastReceiver/Activity. Seems like a sledge hammer for a nail. – Austin Hanson Jul 19 '16 at 19:23
  • Love the comparison :D @AustinHanson – Vucko Jul 19 '16 at 20:23

1 Answers1

1

Use Activity.runOnUiThread(Runnable) to affect some change to your ListView Adapter's backing data model on the main thread. Afterwards, call Adapter.notifyDataSetChanged(). See How to refresh Android listview?

Community
  • 1
  • 1
Austin Hanson
  • 21,820
  • 6
  • 35
  • 41