문제

I am attempting to implement a class for service discovery using Android's NsdManager API. I am wondering how one could start the service search for a fixed amount of time from the main activity, then stop it to use the results of the search?

The NsdManager API says the call should be asynchronous

The API is asynchronous and responses to requests from an application are on listener callbacks on a seperate thread.

I have successfully sent the class a handler which updates my UI thread with the message response but I'm not sure how I can then stop the discovery service after, say, 5 seconds without blocking the Main Thread with a timer :S

I hope it is a relevant question and I have provided enough information.

Br

도움이 되었습니까?

해결책

You don't need to use a timer, just use postDelayed(Runnable r, long millis) on your View. You can call that from any thread, so you could call it from the callback.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top