Danh mục

Bài giảng Lập trình cho thiết bị di động: Chương 5 - ĐH Đồng Nai

Số trang: 61      Loại file: pptx      Dung lượng: 1.90 MB      Lượt xem: 17      Lượt tải: 0    
Thư viện của tui

Phí tải xuống: 28,000 VND Tải xuống file đầy đủ (61 trang) 0
Xem trước 7 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Bài giảng Lập trình cho thiết bị di động: Chương 5 - Networking APIs VÀ Multimedia APIs trình bày các nội dung về Networking APIs và Multimedia APIs. Tham khảo nội dung bài giảng để hiểu rõ hơn về các nội dung trên.
Nội dung trích xuất từ tài liệu:
Bài giảng Lập trình cho thiết bị di động: Chương 5 - ĐH Đồng Nai DONG NAI UNIVERSITY OF TECHNOLOGY API 1 2Networking Multimedia APIs APIs 1 DONG NAI UNIVERSITY OF TECHNOLOGY1. Networking APIs 1.1 Understanding Mobile Networking 1.2 Strict Mode with Networking 1.3 Accessing the Internet (HTTP) 2 DONG NAI UNIVERSITY OF TECHNOLOGY1.1 Understanding Mobile NetworkingØ Networking on the Android platform is standardized, using a combination of powerful yet familiar technologies and libraries such as java.net.Ø Network implementation is generally straightforward, but mobile application developers need to plan for less stable connectivity than one might expect in a home or office network setting—connectivity depends on the location of the users and their devices.Ø developer must take extra care when designing network- enabled applications 3 DONG NAI UNIVERSITY OF TECHNOLOGY 1.2 Strict Mode with NetworkingØ Strict mode is a method that developers can use to detect operations performed on the main thread that should not be there.Ø API Level 11 expanded upon strict mode in ways that impact networking code. By default, if you perform network operations on the main thread, your application throws an exception, specifically android.os.NetworkOnMainThreadException.Ø 2 ways to avoid this is to use proper coding techniques and put all networking operations on a thread other than the main thread (should use AsyncTask class).Ø Or call the permitAll() method to skip strict mode entirely 4 DONG NAI UNIVERSITY OF TECHNOLOGY 1.2 Strict Mode with Networking Ø If you want to use networking in Main Thread, the coding:if (android.os.Build.VERSION.SDK_INT > 10) { StrictMode.ThreadPolicy policy = newStrictMode.ThreadPolicy.Builder() .permitAll().build(); StrictMode.setThreadPolicy(policy);}This is not recommended for production applications. WHY?The next slide you will learn 3 ways to create Thread for networking, tosee details please click the link below:http://android-developers.blogspot.com/2009/05/painless-threading.html 5 DONG NAI UNIVERSITY OF TECHNOLOGY 1.2 Strict Mode with Networking Ø 1 - If not, you must write coding on a Thread otherAt first, this code seems to be a good solution to your problem,as it does not block the UI thread. Unfortunately, it violates thesingle thread model: the Android UI toolkit is not thread-safeand must always be manipulated on the UI thread. In thispiece of code, the ImageView is manipulated on a workerthread, which can cause really weird problems. Tracking downand fixing such bugs can be difficult and time-consuming. 6 DONG NAI UNIVERSITY OF TECHNOLOGY 1.2 Strict Mode with Networking Ø 2 - If not, you must write coding on a Thread otherUnfortunately, these classes and methods also tend to makeyour code more complicated and more difficult to read. Itbecomes even worse when your implement complexoperations that require frequent UI updates. 7 DONG NAI UNIVERSITY OF TECHNOLOGY1.2 Strict Mode with NetworkingØ 3 - If not, you must write coding on a Thread other ü Android 1.5 offers a new utility class, called AsyncTask, that simplifies the creation of long-running tasks that need to communicate with the user interface. The goal of AsyncTask is to take care of thread management for you. 8 DONG NAI UNIVERSITY OF TECHNOLOGY1.3 Accessing the Internet (HTTP)ü The most common way to transfer data to and from the network is to use HTTP. You can use HTTP to encapsulate almost any type of data and to secure the data with Secure Sockets Layer (SSL) Objectives: q Reading Data from the Web q Using HttpURLConnection q Displaying Images from a Network Resource q Retrieving Android Network Status 9 ...

Tài liệu được xem nhiều:

Gợi ý tài liệu liên quan: