Reputation: 1415
CFRunLoop or NSRunLoop in Java Android.
At glance (and from IOS Documentation) CFRunLoop seem equivalent to handler and Looper in Android...but it 's used also to receive notification and callback from network etc...(unclear for me)...
I need help to understand the use of this class in general to help find an good equivalent in android or implement my own one.
Thanks,
Upvotes: 0
Views: 730
Reputation: 1586
I don't think Android architecture have a runloop implementation in the main thread, In Android the main thread have a event handler that handles touch events, broadcast listeners, activity life cycle callbacks ... but they don't handle the stream events from sockets(event like data received from the socket).
we need to handle these events in the separate thread and if we need to do some UI changes from this thread we need to use Loopers to pass the message to the main thread handler, since we know that UI changes cant be done in other threads.
But in IOS NSRunLoop helps us to handle these events in the main loop instead of getting our hands in to multithreading issue. NSRunloop does not create a separate thread but instead uses the same threads to handle the events.
We should be careful about the event being added using NSRunloop, if it is going to take few seconds, it is better to use NSThread instead of NSRunLoop which will block the main thread from handling touch events.
I attach the links that will helped me to understand these concepts, about NSRunloop and about handlers and loopers
Upvotes: 1
Reputation: 76
NSRunLoop is a wrapper of CFRunLoop.
As an iOS developer transfered from android, I can tell you that NSRunLoop and CFRunLoop 's equivalent in android is Looper, though there is a little difference between RunLoop and Looper.
And the usage between RunLoop and Looper is different. About RunLoop's usage, you can take a look at this link:
https://stackoverflow.com/a/12092176/2805488
And yet for android Looper's usage:
http://developer.android.com/reference/android/os/Looper.html
Upvotes: 2