質問

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