Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a thread in Android NDK?

Can anyone tell me how to create a thread in Android NDK? I'm porting some C++ code from Win32 to Android, I don't know what's the NDK API corresponding to Win32 API AfxBeginThread(). Thanks!

like image 719
airun Avatar asked Nov 30 '11 09:11

airun


People also ask

How are threads executed in Android?

When an application is launched in Android, it creates the primary thread of execution, referred to as the “main” thread. Most thread is liable for dispatching events to the acceptable interface widgets also as communicating with components from the Android UI toolkit.

What is UI thread in Android?

User Interface Thread or UI-Thread in Android is a Thread element responsible for updating the layout elements of the application implicitly or explicitly. This means, to update an element or change its attributes in the application layout ie the front-end of the application, one can make use of the UI-Thread.

What are the main two types of threads in Android?

There're 3 types of thread: Main thread, UI thread and Worker thread. Main thread: when an application is launched, the system creates a thread of execution for the application, called main.

What is main thread and background thread in Android?

For example, if your app makes a network request from the main thread, your app's UI is frozen until it receives the network response. You can create additional background threads to handle long-running operations while the main thread continues to handle UI updates.


1 Answers

Android NDK (partially) support POSIX thread, so you can use pthread_create.

like image 179
pierrotlefou Avatar answered Oct 16 '22 12:10

pierrotlefou