Java 8 in Android N 366 Setup 366

Java 8 in Android N 366 Setup 366

[ 1 ] Android High Performance Programming Build fast and efficient Android apps that run as reliably as clockwork in a multi-device world Enrique López Mañas Diego Grancini BIRMINGHAM - MUMBAI Android High Performance Programming Copyright © 2016 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: August 2016 Production reference: 1240816 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78528-895-1 www.packtpub.com Credits Authors Project Coordinator Enrique López Mañas Ritika Manoj Diego Grancini Proofreader Reviewer Safis Editing Emil Stefanov Atanasov Indexer Commissioning Editor Hemangini Bari Edward Gordon Graphics Acquisition Editor Kirk D'Penha Larissa Pinto Production Coordinator Content Development Editor Arvindkumar Gupta Parshva Sheth Cover Work Technical Editor Arvindkumar Gupta Prajakta Mhatre Copy Editor Safis Editing About the Authors Enrique López Mañas is a Google Developer Expert and independent IT consultant. He has been working with mobile technologies and learning from them since 2007. He is an avid contributor to the open source community and a FLOSS (Free Libre Open Source Software) kind of guy, being among the top 10 open source Java contributors in Germany. He is a part of the Google LaunchPad accelerator, where he participates in Google global initiatives to influence hundreds of the best startups from all around the globe. He is also a big data and machine learning aficionado. In his free time he rides his bike, take pictures, and travels until exhaustion. He also writes literature and enjoys all kinds of arts. He likes to write about himself in third person. You can follow him on Twitter (@eenriquelopez) to stay updated on his latest movements. Diego Grancini has a degree in telecommunications and IT engineering from Perugia University. He has developed his skills on Android development for more than six years leading and contributed to several projects, teaching and sharing his skills during his career. He joined Engineering Ingegneria Informatica S.P.A. after his degree, defining his own knowledge about Java and Android development working as the lead Android developer for years. Then he joined J.P. Morgan & Chase, strengthening his skills about security and performance in software development and Android platform in particular. I would like to express my gratitude to Murvin Bhantooa, for helping me with content, Gil McErlane and all of my colleagues in J.P. Morgan & Chase for supporting, and Gianluca Polegri and all of my ex-colleagues at Engineering Ingegneria Informatica S.P.A. for laying the foundations of my knowledge. Thanks to my father Augusto for guiding and forming me, my mother Argia Flavia, my sister Agostina, the rest of my family and Utah Capo for supporting me. Special thanks to Helen McKenna for building my language skills. I would like to thank Enrique López Mañas, Parshva Sheth, and Emil Atanasov for the great job they did in the development of this book. Last but not least, I ask forgiveness for having failed to mention people who were with me during my journey. About the Reviewer Emil Atanasov is an IT consultant with broad experience in mobile technologies. He has been exploring the field of mobile development since 2006. Emil has a MSc in media informatics from RWTH Aachen University, Germany, and a MSc in computer science from Sofia University "St. Kliment Ohridsky," Bulgaria. He has worked for several huge USA companies and has been a freelancer for several years. Emil has experience in software design and development. He was involved in the process of redesigning, improving, and creating a number of mobile apps. Currently, he is focused on the rapidly growing mobile sector and manages a great team of developers that provides software solutions to clients around the world. He is a co-founder of ApposeStudio Inc. As an Android team leader and project manager, Emil was leading a team that was developing a part of the Nook Color firmware—an e-magazine/e-book reader, which supports the proprietary Barnes & Nobel and some other e-book formats. He is one of the people behind the Getting Started with Flurry Analytics book. He also contributed heavily to the book Objective-C Memory Management Essentials and Android Application Development Cookbook, Second Edition. I want to thank my family and friends for being so cool. Thank you for supporting me even though I'm such a bizarre geeky person, who spends most of the time in the digital world. Thank you, guys! www.PacktPub.com eBooks, discount offers, and more Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM https://www2.packtpub.com/books/subscription/packtlib Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books. Why subscribe? • Fully searchable across every book published by Packt • Copy and paste, print, and bookmark content • On demand and accessible via a web browser This book is dedicated to you, dear reader. Because it is you who make the writing endeavor meaningful. – Enrique López Mañas I dedicate this book to Anna: you complete me. – Diego Grancini Table of Contents Preface ix Chapter 1: Introduction: Why High Performance? 1 Why does the performance of an application mean so much to so many? 2 Manual testing and automatic testing 3 ANR and delays in software 4 What triggers ANRs and how can I avoid them? 4 Android architecture 4 Dalvik Virtual Machine 5 Memory management 6 Energy consumption 7 Java language 8 Native Development Kit or how to develop with native code when needed 8 Three limits in application responsiveness 9 Business value of software quality 9 Summary 11 Chapter 2: Efficient Debugging 13 Android Debug Bridge 13 Dalvik Debug Monitor Server 15 Capturing and analyzing thread information 16 Heap analysis and visualization 19 Allocation tracker 21 Network usage 23 Emulator Control 24 System status 25 Debugging the UI 26 Profiling with Hierarchy Viewer 28 [ i ] Table of Contents Systrace 30 Android device debug options 31 Android Instant Run 41 GPU profiler 43 Running a trace 44 ClassyShark 45 Getting started 45 Summary 50 Chapter 3: Building Layouts 51 Walkthrough 51 Rendering performance 52 Screen tearing and VSYNC 54 Hardware acceleration 57 Overdraw 60 Multi-window mode 61 Overview 62 Configuration 64 Management 65 Drag and drop 67 Performance impact 67 Best practices 67 Provided layout overview 67 Hierarchical layout management 68 Reusing layouts 74 ViewStub 77 AdapterViews and view recycling 77 The ViewHolder pattern 80 Custom views and layouts 82 Screen zoom 87 Debugging tools 89 The Design view 90 Hierarchy Viewer 92 Tree View 92 View properties 94 Tree overview 95 Layout View 96 On device tools 96 Debugging GPU overdraw 97 Profile GPU rendering 98 Systrace 104 Summary 107 [ ii ] Table of Contents Chapter 4: Memory 109 Walkthrough 109 How memory works 110 Garbage collection 110 Shared memory 111 Runtime 111 Android N JIT compiler 112 Memory leak 113 Memory churn 114 References 114 Memory-side projects 115 Project Svelte and Android N 115 Best practices 117 Data types 117 Autoboxing 118 Sparse array family 120 ArrayMap 123 Syntax 124 Collections 124 Enumerations 127 Constants 130 Object management 130 Strings 131 String concatenation 131 Local variables 132 Arrays versus collections 133 Streams 133 Memory patterns 135 The object pool pattern 135 The FlyWeight pattern 139 Android component leaks 142 Activities 143 Services 154 Processes 155 The memory API 155 Main components and memory management 158 Debugging tools 160 LogCat 160 Dalvik 161 ART 162 The ActivityManager API 163 StrictMode 164 [ iii ] Table of Contents Dumpsys 165 Meminfo 166 ProcStats 168 Summary 172 Chapter 5: Multithreading 173 Walkthrough 174 Threading basics 174 Multicore CPUs 174 Threads 175 Multithreaded applications 177 Thread safety 178 Android multithreading environment 178 Processes 179 Android application thread 179 The UI thread 180 Worker threads 180 The binder thread 181 Android thread messaging 181 Best practices 183 Threads 183 HandlerThread 184 When to use 185 AsyncTask 185 Methods 186 Generics parameters 186 States management 187 Executor

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    412 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us