Efficient Android Threading. Asynchronous Processing Techniques for Android Applications - Helion
ISBN: 978-14-493-6409-0
stron: 280, Format: ebook
Data wydania: 2014-05-22
Księgarnia: Helion
Cena książki: 152,15 zł (poprzednio: 176,92 zł)
Oszczędzasz: 14% (-24,77 zł)
Multithreading is essential if you want to create an Android app with a great user experience, but how do you know which techniques can help solve your problem? This practical book describes many asynchronous mechanisms available in the Android SDK, and provides guidelines for selecting the ones most appropriate for the app you’re building.
Author Anders Goransson demonstrates the advantages and disadvantages of each technique, with sample code and detailed explanations for using it efficiently. The first part of the book describes the building blocks of asynchronous processing, and the second part covers Android libraries and constructs for developing fast, responsive, and well-structured apps.
- Understand multithreading basics in Java and on the Android platform
- Learn how threads communicate within and between processes
- Use strategies to reduce the risk of memory leaks
- Manage the lifecycle of a basic thread
- Run tasks sequentially in the background with HandlerThread
- Use Java’s Executor Framework to control or cancel threads
- Handle background task execution with AsyncTask and IntentService
- Access content providers with AsyncQueryHandler
- Use loaders to update the UI with new data
Osoby które kupowały "Efficient Android Threading. Asynchronous Processing Techniques for Android Applications", wybierały także:
- Kotlin w praktyce. Kurs video. Tworzenie aplikacji webowych za pomocą Spring Boota 79,00 zł, (31,60 zł -60%)
- Platforma Xamarin. Kurs video. Poziom drugi. Zaawansowane techniki tworzenia aplikacji cross-platform 99,00 zł, (39,60 zł -60%)
- Android Studio. Kurs video. Narzędzia Android developera 69,00 zł, (31,05 zł -55%)
- Android. Techniki efektywnej pracy. Kurs video. Poziom pierwszy. Skróty klawiszowe i biblioteki 59,00 zł, (26,55 zł -55%)
- Testowanie aplikacji mobilnych na platformę Android. Kurs video. Poziom pierwszy. Testy jednostkowe i UI 59,00 zł, (26,55 zł -55%)
Spis treści
Efficient Android Threading. Asynchronous Processing Techniques for Android Applications eBook -- spis treści
- Efficient Android Threading
- Dedication
- Preface
- Audience
- Contents of This Book
- Conventions Used in this Book
- Using Code Examples
- Safari Books Online
- How to Contact Us
- Acknowledgements
- 1. Android Components and the Need for Multiprocessing
- Android Software Stack
- Application Architecture
- Application
- Components
- Activity
- Service
- ContentProvider
- BroadcastReceiver
- Application Execution
- Linux Process
- Lifecycle
- Application start
- Application termination
- Structuring Applications for Performance
- Creating Responsive Applications Through Threads
- Summary
- I. Fundamentals
- 2. Multithreading in Java
- Thread Basics
- Execution
- Single-Threaded Application
- Multithreaded Application
- Increased resource consumption
- Increased complexity
- Data inconsistency
- Thread Safety
- Intrinsic Lock and Java Monitor
- Synchronize Access to Shared Resources
- Using the intrinsic lock
- Using explicit locking mechanisms
- Example: Consumer and Producer
- Task Execution Strategies
- Concurrent Execution Design
- Summary
- Thread Basics
- 3. Threads on Android
- Android Application Threads
- UI Thread
- Binder Threads
- Background Threads
- The Linux Process and Threads
- Scheduling
- Priority
- Control groups
- Scheduling
- Summary
- Android Application Threads
- 4. Thread Communication
- Pipes
- Basic Pipe Use
- Example: Text Processing on a Worker Thread
- Shared Memory
- Signaling
- BlockingQueue
- Android Message Passing
- Example: Basic Message Passing
- Classes Used in Message Passing
- MessageQueue
- MessageQueue.IdleHandler
- Example: Using IdleHandler to terminate an unused thread
- Message
- Initialized
- Pending
- Dispatched
- Recycled
- Looper
- Looper termination
- The UI thread Looper
- Handler
- Setup
- Message creation
- Message insertion
- Example: Two-way message passing
- Message processing
- Removing Messages from the Queue
- Observing the Message Queue
- Taking a snapshot of the current message queue
- Tracing the message queue processing
- Communicating with the UI Thread
- Summary
- Pipes
- 5. Interprocess Communication
- Android RPC
- Binder
- AIDL
- Synchronous RPC
- Asynchronous RPC
- Message Passing Using the Binder
- One-Way Communication
- Two-Way Communication
- Summary
- Android RPC
- 6. Memory Management
- Garbage Collection
- Thread-Related Memory Leaks
- Thread Execution
- Inner classes
- Static inner classes
- The lifecycle mismatch
- Thread Communication
- Sending a data message
- Posting a task message
- Thread Execution
- Avoiding Memory Leaks
- Use Static Inner Classes
- Use Weak References
- Stop Worker Thread Execution
- Retain Worker Threads
- Clean Up the Message Queue
- Summary
- 2. Multithreading in Java
- II. Asynchronous Techniques
- 7. Managing the Lifecycle of a Basic Thread
- Basics
- Lifecycle
- Interruptions
- Uncaught Exceptions
- Thread Management
- Definition and Start
- Anonymous inner class
- Public thread
- Static inner class thread definition
- Summary of options for thread definition
- Retention
- Retaining a thread in an Activity
- Retaining a thread in a Fragment
- Definition and Start
- Summary
- Basics
- 8. HandlerThread: A High-Level Queueing Mechanism
- Fundamentals
- Lifecycle
- Use Cases
- Repeated Task Execution
- Related Tasks
- Example: Data persistence with SharedPreferences
- Task Chaining
- Example: Chained network calls
- Conditional Task Insertion
- Summary
- 9. Control over Thread Execution Through the Executor Framework
- Executor
- Thread Pools
- Predefined Thread Pools
- Custom Thread Pools
- ThreadPoolExecutor configuration
- Designing a Thread Pool
- Sizing
- Dynamics
- Bounded or unbounded task queue
- Thread configuration
- Extending ThreadPoolExecutor
- Lifecycle
- Shutting Down the Thread Pool
- Thread Pool Uses Cases and Pitfalls
- Favoring thread creation over queuing
- Handling preloaded task queues
- The danger of zero core threads
- Task Management
- Task Representation
- Submitting Tasks
- Individual submission
- invokeAll
- invokeAny
- Rejecting Tasks
- ExecutorCompletionService
- Summary
- 10. Tying a Background Task to the UI Thread with AsyncTask
- Fundamentals
- Creation and Start
- Cancellation
- States
- Example: Limiting an AsyncTask execution to one at the time
- Implementing the AsyncTask
- Example: Downloading Images
- Background Task Execution
- Application Global Execution
- Execution Across Platform Versions
- Custom Execution
- Example: Nonglobal sequential execution
- AsyncTask Alternatives
- When an AsyncTask Is Trivially Implemented
- Background Tasks That Need a Looper
- Local Service
- Using execute(Runnable)
- Summary
- Fundamentals
- 11. Services
- Why Use a Service for Asynchronous Execution?
- Local, Remote, and Global Services
- Creation and Execution
- Lifecycle
- Started Service
- Implementing onStartCommand
- Options for Restarting
- User-Controlled Service
- Example: Bluetooth connection
- Task-Controlled Service
- Example: Concurrent download
- Bound Service
- Local Binding
- Choosing an Asynchronous Technique
- Summary
- 12. IntentService
- Fundamentals
- Good Ways to Use an IntentService
- Sequentially Ordered Tasks
- Example: Web service communication
- Asynchronous Execution in BroadcastReceiver
- Example: Periodical long operations
- Sequentially Ordered Tasks
- IntentService Versus Service
- Summary
- 13. Access ContentProviders with AsyncQueryHandler
- Brief Introduction to ContentProvider
- Justification for Background Processing of a ContentProvider
- Using the AsyncQueryHandler
- Example: Expanding Contact List
- Understanding the AsyncQueryHandler
- Limitations
- Summary
- 14. Automatic Background Execution with Loaders
- Loader Framework
- LoaderManager
- initLoader vs restartLoader
- LoaderCallbacks
- AsyncTaskLoader
- LoaderManager
- Painless Data Loading with CursorLoader
- Using the CursorLoader
- Example: Contact list
- Adding CRUD Support
- Example: Use CursorLoader with AsyncQueryHandler
- Implementing Custom Loaders
- Loader Lifecycle
- Background Loading
- Example: Simple custom loader
- Content Management
- Delivering Cached Results
- Example: Custom File Loader
- Handling Multiple Loaders
- Summary
- Loader Framework
- 15. Summary: Selecting an Asynchronous Technique
- Keep It Simple
- Thread and Resource Management
- Message Communication for Responsiveness
- Avoid Unexpected Task Termination
- Easy Access to ContentProviders
- A. Bibliography
- Books
- Articles
- Presentations
- 7. Managing the Lifecycle of a Basic Thread
- Index
- Colophon
- Copyright