tailieunhanh - Bài giảng Lập trình cho thiết bị di động: Chương 4 - Trần Duy Thanh

Bài giảng Lập trình cho thiết bị di động: Chương 4 trình bày các nội dung sau: Multi - Threading, Intent filter, Broadcast Receiver, Android Services, Webservice .Net,.! | 1 5. Webservice .Net 4. Android Services 3. Broadcast Receiver 2. Intent filter 1. Multi - Threading 1 2 1. Multi - Threading Introduction Handler class AsyncTask class 2 3 Introduction Threads Android’s threads run in a manner similar to common Java threads A Thread is a concurrent unit of execution. not executing in order has its own call stack for methods being invoked, their arguments and local variables. Each virtual machine instance has at least one main Thread running when it is started; The application might decide to launch additional Threads for specific purposes. 3 4 Introduction Multi- Threading 4 5 Introduction Multi- Threading Threads in the same VM interact and synchronize by the use of shared objects and monitors associated with these objects. There are basically two main ways of having a Thread execute application code. a new class that extends Thread and override its run() method. a new Thread instance passing to it a Runnable object. In both cases, the start() method must be called to actually execute the new Thread. 5 6 Introduction Advantages of Multi- Threading Threads share the process' resources but are able to execute independently. Applications responsibilities can be separated main thread runs UI, and slow tasks are sent to background threads. Threading provides an useful abstraction of concurrent execution. Particularly useful in the case of a single process that spawns multiple threads on top of a multiprocessor system. In this case real parallelism is achieved. Consequently, a multithreaded program operates faster on computer systems that have multiple CPUs. 6 7 Introduction Disadvantages of Multi- Threading Code :more complex Need to detect, avoid, resolve deadlocks Threads not executing in order Runnable Thread? What different? Deadlock and Atomic type 7 8 Handler class An application may involve a time-consuming operation, however we want the UI to | 1 5. Webservice .Net 4. Android Services 3. Broadcast Receiver 2. Intent filter 1. Multi - Threading 1 2 1. Multi - Threading Introduction Handler class AsyncTask class 2 3 Introduction Threads Android’s threads run in a manner similar to common Java threads A Thread is a concurrent unit of execution. not executing in order has its own call stack for methods being invoked, their arguments and local variables. Each virtual machine instance has at least one main Thread running when it is started; The application might decide to launch additional Threads for specific purposes. 3 4 Introduction Multi- Threading 4 5 Introduction Multi- Threading Threads in the same VM interact and synchronize by the use of shared objects and monitors associated with these objects. There are basically two main ways of having a Thread execute application code. a new class that extends Thread and override its run() method. a new Thread instance passing to

TỪ KHÓA LIÊN QUAN