Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Threading Example in Android [closed]

I want some simple example on thread creation and invoking of threads in android.

like image 445
ram Avatar asked Jan 18 '11 10:01

ram


People also ask

What is thread in android with example?

A thread is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently. Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority.

What are the main two type of thread 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.

Is android multi threading?

Working on multiple tasks at the same time is Multitasking. In the same way, multiple threads running at the same time in a machine is called Multi-Threading. Technically, a thread is a unit of a process.

How does the threading work 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.


2 Answers

This is a nice tutorial:

http://android-developers.blogspot.de/2009/05/painless-threading.html

Or this for the UI thread:

http://developer.android.com/guide/faq/commontasks.html#threading

Or here a very practical one:

http://www.androidacademy.com/1-tutorials/43-hands-on/115-threading-with-android-part1

and another one about procceses and threads

http://developer.android.com/guide/components/processes-and-threads.html

like image 81
RoflcoptrException Avatar answered Oct 09 '22 19:10

RoflcoptrException


One of Androids powerful feature is the AsyncTask class.

To work with it, you have to first extend it and override doInBackground(...). doInBackground automatically executes on a worker thread, and you can add some listeners on the UI Thread to get notified about status update, those functions are called: onPreExecute(), onPostExecute() and onProgressUpdate()

You can find a example here.

Refer to below post for other alternatives:

Handler vs AsyncTask vs Thread

like image 33
Endian Ogino Avatar answered Oct 09 '22 17:10

Endian Ogino