I tried implementing a network service discovery and setting the name into a textView after successful registration. But I am getting an android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
exception. My basic structure looks like this:
NsdManager.RegistrationListener mRegistrationListener;
onCreate() {
mRegistrationListener = new NsdManager.RegistrationListener() {
onServiceRegistered(serviceInfo) {
TextView textView = (TextView) findViewById(R.id.nsdServiceNameText);
textView.setText(serviceInfo.getServiceName());
}
}
mNsdManager = (NsdManager) this.getBaseContext().getSystemService(Context.NSD_SERVICE);
mNsdManager.registerService(
serviceInfo,
NsdManager.PROTOCOL_DNS_SD,
mRegistrationListener);
}
It makes sense to me that I may be in the wrong context to edit the view but how did I get there and more importantly how do I solve this?