Looking for:
Expert android studio pdf free free

Git stats 17 commits. Failed to load latest commit information. View code. About the Book The book deep dives into understanding the design, develop, and distribute mechanism of building restaurant discovery app features that can be served “hot” to the end users.
Instructions and Navigation All of the code is organized into folders. MIT license. Releases No releases published. Packages 0 No packages published. Page Count.
Murat Yener, Onur Dundar,. Discover the basics of working in Android Studio and Gradle, as well as the application architecture of the latest Android platform Understand Native Development Kit and its integration with Android Studio Complete your development lifecycle with automated tests, dependency management, continuos integration and release management Writing your own Gradle plugins to customize build cycle Writing your own plugins for Android Studio to help your development tasks.
An overview of Android Studio is included covering areas such as tool windows, the code editor and the user interface Designer tool. An introduction to the architecture of Android is followed by an in-depth look at the design of Android applications and user interfaces using Android Studio. More advanced topics such as database management, content providers and intents are also covered, as are touch screen handling, gesture recognition, camera access and the playback and recording of both video and audio.
This edition of the book also covers features introduced with Android 4. In addition to covering general Android development techniques, the book also includes Google Play specific topics such as implementing maps using the Google Maps Android API, in-app billing and submitting apps to the Google Play Developer Console.
Chapters also cover advanced features of Android Studio such as Gradle build configuration and the implementation of build variants to target multiple Android device types from a single project code base. Assuming you already have some Java programming experience, are ready to download Android Studio and the Android SDK, have access to a Windows, Mac or Linux system and ideas for some apps to develop, you are ready to get started.
We have Android guides for everyone whether you are a beginner, intermediate or expert. We will go through these categories one by one. Bloaters Bloaters are codes, methods, and classes that have increased largely in size and have become hard to work with.
They accumulate over time as the functionality increases and nobody tries to resolve it: Long method: A long method is a method that contains too many lines of code.
Generally, any method longer than 10 lines is long. Large class: A class that contains many lines of code formed by many fields and methods. Primitive obsession: Primitive obsession occurs if primitives for example, string and int are used instead of small objects for simple tasks such as user first names, user last names, user emails, user phone numbers, and so on. They could be clubbed in separate objects, such as users use of string constants as field names for use in data arrays.
Long parameter list: More than three or four parameters for a method is too many. Data clumps: Different parts of the code with identical groups of variables with similar causes. These clumps should be turned into their own classes. Object-orientation abusers These pieces of code smell because the application of object-oriented programming principles is not being applied on the code correctly: Switch statements: Your switch statement has been made complex, or the operator used is complex.
It could also occur if a sequence of if statements is used instead of a switch. If these circumstances do not occur, then these objects or fields lead to code smell. Refused bequest: A subclass may have access to multiple methods from its parent class.
But what if it is actually using only a few of the methods from it, and the others are just present because they are given to the subclass.
If a subclass uses only some of the methods and properties inherited from its parents, the unneeded methods may simply go unused. Alternative classes with different interfaces: The code smells if two or more classes have the same functionality, but what differs is only either the name of the class or the functions. Change preventers If you change the code in one place, then you will need to change it in the other places where the code is dependent.
This affects the development process because it requires unnecessary additional handling, which is time consuming: Divergent change: If you have to make many unrelated methods while making a change in one class then the change is divergent. For example, when adding a new restaurant type, you have to change the methods for finding, and displaying, restaurants.
Shotgun surgery: If you need to do a small modification at one place, then it requires that you make many small changes to many different classes. Parallel inheritance hierarchies: When creating a subclass for a class, if it requires creating a subclass for another class related to it, then it is parallel inheritance.
Duplicate code: More than one codes that are almost identical used in different places. Lazy class: If a class is not performing any major functionality and the functionality written seems to be unnecessary, then such a class should be deleted.
Data class A data class refers to a class that contains only fields and crude methods for accessing them getters and setters. These are simply containers for data used by other classes. These classes do not contain any additional functionality and cannot operate independently on the data that they own: Dead code: If a variable, field, method, or class is not made use of anywhere in your code, or if there is an old code that is no longer used, then that code is dead and should be deleted using a good IDE.
Speculative generality: A class, method, field, or parameter which was speculated to be made use of in the future but was never made use of.
Such unused code is categorized as speculative generality. Couplers Excessive coupling between classes and methods leads to code smell that is categorized into coupling smells: Feature envy: Data of another object is made use of by a method, more than its own data.
Such code smells after fields are moved to a data class. Message chains: A code makes a series of calls, like one method calling another, and that method in turn calling another method: method1 method2 method3. Middle man: If a class calls another class, and performs only the one function of calling the other class, then the middle class smells. How do I refactor my code? Once you identify the category your smelling code falls into, it’s time for you to refactor it and remove all code smells.
Here we will find how to do some minor tweaks in our code, and they will solve a lot of your problems. Refactoring of methods One of the causes of code smells is the way in which methods are written: how the code has been written in these methods, whether the methods have been written correctly, whether some necessary methods have been written where they should be written, whether too many unnecessary methods have been written, how complex a method has been made, making difficult to understand , or how long and extensive a method is made by adding long code.
Thus, the refactoring in these would comprise of solving the issues in these methods. Some of these techniques are described next. Extract method What is the issue?
You have a long piece of continuous code that becomes too lengthy to be used as a single piece of code. This long code does one kind of work but it is in between or along with the other code that performs another functionality. How do you solve it? Create a new method and write the code in this new, separate method, which will not affect the current functionality. This method can be called from the place where you were actually writing the lengthy code.
This will make the code get clubbed into a method, and make it more readable. When the content of a method is very small or it doesn’t serve a purpose, keeping it in that method and clubbing it along with some other piece of code.
Here, the method could be completely removed and the content from the method could be directly replaced in the code where the method was called.
The inline method could be explained using the following code. We have a method to check if the stock is limited. The result of an expression, which is simple and direct to understand, is stored in a temporary variable, and that variable is made use of only once. Delete the temporary variable by making use of the expression itself, instead of the variable. Consider the example of an inline method here, where, and once again, whose functions are finding if the stock is limited.
One local variable inside a method saves values of different expressions for the statements at various places.
Different variables need to be created for each of the statements inside the method. The same variable should not be reused. Replace method with method object What is the issue? Here, the problem is similar to the problem you had for the extract method: the code in a method has become too long, but in this case you cannot club the code into a method, as the local variables are dependent on each other at multiple places.
The whole code in the method can be compiled into a separate class, as a dependent local variable could be made use of inside that class as per your needs. So this is an extraction of the code into a class instead of a method. The problem here is that the current algorithm written in your method is not the best way to write it. You might have a better way to write the same algorithm. Change the existing code in the method with a new code, without changing the output of the method, but by changing the algorithm.
But is the algorithm used here the best one to get the remainder? It is not, because the remainder could be found using the mod operator directly. Keeping your code clean is very important, as it improves the readability of the code. It also has other advantages in that it makes your code simple and reduces code duplication.
It could reduce the number of lines in the code, thus reducing the size of your whole final product. First, you need to understand and learn where your code smells and what smell your code has. Then, apply the right refactoring technique to remove the code smell. Thus, understanding the refactoring methods turns out to be crucial. A lot of apps today are resource eaters. Even though they might be the best at the user interface and experience, if they end up eating too many of resources of the phone, the app might just face an uninstalled state within no time.
The battery is one such dear factor to the user and still remains a point of consideration while choosing a smartphone. In this section, we will discuss several performance avenues in an app that we must cater to to ensure that we are building a performance-centric app which is resource friendly.
We will list some of the tools we can use to improve the app performance too. Improving display performances After the UIs are designed, the most common issues developers face is the performance of UIs on devices.
This chapter will help to identify problems in an app’s layout performance and improve the UI responsiveness. Optimizing layouts Optimizing layouts becomes the most important part, as far as user experience is concerned, because the layout is the aspect of the app which is finally seen by the user. They are the interface between the user and the app.
How the app looks and how it plays with the user’s experience is all decided by the layout. So, making the layout user friendly and optimized is important. Performance Matters Optimizing layout hierarchies Android has many standard layouts that can be used to design the layout. Using these layouts means that each layout has to be added to your application. The app is also required to initialize it, and the layout later requires to be drawn.
Layout hierarchy is making use a layout within another parent layout. For example, using nested instances of RelativeLayout or LinearLayout. Using such nested layouts is a very costly way of doing layout drawing work, because it requires a lot of processing to be done.
A larger weight value means that it allows the layout to be expanded to fill any remaining space in the parent view. It is more important to optimize the layout when it is used in a list or a grid as, otherwise, it can lead to lagging of the view. Optimization of such layouts requires us to perform stepwise checking of the layout and improve it by changing the layout code wherever possible. Android Studio provides you with tools to check for hierarchies in your layout, analyze them, and fix them based on the analysis.
Two of sthe tools provided are mentioned and explained below: Hierarchy Viewer: Hierarchy Viewer is a tool that Android Studio provides to analyze the layouts in Android. Once your layouts are ready, you need to inspect those layouts in Hierarchy Viewer. Hierarchy Viewer allows you to analyze your layout while your application is running.
This tool finds out the cost for drawing each of the layouts and analyzes the performance of each of the elements in the layout. It asks user to select running processes on a connected device or emulator.
It then displays the layouts from all these processes, in a layout tree. Once the hierarchy viewer draws the layouts, it analyzes it and shows the performance of each layout using traffic lights. The traffic lights on each block indicate its Measure, Layout, and Draw performance. This can be understood by considering the example of an item in RecyclerView: Figure 5.
Layout item of a RecyclerView. The layout shows a bitmap image on the left and two TextViews to display text on the right. As in a RecyclerView, the same layout has to be inflated multiple times. Such a layout need to be optimized as it would otherwise increase the performance. Once you open Hierarchy Viewer, it will show a list of available devices and their running components. Choose your component and click Hierarchy View to view the layout hierarchy of the selected component.
Figure 5. Layout hierarchy for the layout in Figure 5. The above layout has to be improved on performance by changing the layout code and removing the nested layout in the code. This can be done using a RelativeLayout instead of a LinearLayout, keeping the layout design intact. When this design is converted to use RelativeLayout, the layout becomes a two-level hierarchy. After changing the code and running the Hierarchy Viewer the view is as shown in Figure 5.
The nested view of the layout is removed in this case, and the performance of the layout is improved. But this performance improvement is a small one, considering this single layout. However, its value increases as it is used in a RecyclerView, and this layout would be inflated multiple times. Lint is a tool that it is integrated into Android Studio and you need to write rules which run automatically whenever you compile your program.
With Android Studio, lint can perform inspections for a specific build variant or for all build variants. Some examples of lint rules are: Use compound drawables: A LinearLayout which contains an ImageView and a TextView can be more efficiently handled as a compound drawable. Merge root frame: If a FrameLayout is the root of a layout and does not provide background or padding, it can be replaced with a merge tag which is slightly more efficient.
Useless leaf: A layout that has no children or no background can often be removed since it is invisible for a flatter and more efficient layout hierarchy. Useless parent: A layout with children that has no siblings, is not a ScrollView or a root layout, and does not have a background, can be removed and have its children moved directly into the parent for a flatter and more efficient layout hierarchy.
Deep layouts: Layouts with too much nesting are bad for performance. Consider using flatter layouts such as RelativeLayout or GridLayout to improve performance.
The default maximum depth is The Inspection Configuration page appears with the supported inspections: Lint has the ability to automatically fix some issues, provide suggestions for others, and jump directly to the offending code for review. The layout optimization could also occur by reusing some layouts that are already present, as that makes the layout more efficient.
Reusing layouts allows you to create reusable complex layouts, such as an action bar panel or a custom progress bar with a description. Here, the elements of your application that are common across multiple layouts can be extracted and managed separately and later be included in each layout.
So, while you can create individual UI components by writing a custom view, you can do it even more easily by re-using a layout file. The methods to make a reusable layout are mentioned below. Re-using layouts with : This method of re-using of a layout can be done using an statement in your XML code and including the already existing layout file into the current layout. One is by creating a new layout, which you know you will be reusing, from scratch, and the second is to make a piece of existing code into a separate layout file and later use it at another place.
That could be done by using the tag in the code where the layout has be included. Reusing layout is a powerful feature that allows developers to create reusable complex layouts. A point to be noted is that any elements of your app that are common across multiple layers can be extracted and managed separately.
Afterwards, they can be included in each layout. The above layout is included in another layout, as shown in the code below Use the Tag: The layout can be also reused using the tag; this helps to eliminate redundant view groups in your view hierarchy.
The merge is useful mostly when your main layout is a vertical LinearLayout in which two consecutive views can be reused in multiple layouts. In this case, the reusable layout in which you place the two views requires its own root view. However, using another LinearLayout as the root for the re-usable layout would result in a vertical LinearLayout inside a vertical LinearLayout.
This can slow performance. Instead, a tag could be used to avoid this redundancy. A code example of a merge has been show in the following code example below: [ ] Performance Matters The tag is used to mitigate the number of the levels and to increase the performance of rendering layout. The merge layout should also be included in the layout using the tag. When you include this layout in another layout, the system ignores the element and places the two buttons directly in the layout, in place of the tag.
Note that can only be used as the root tag of an XML layout. Views on demand Some of the layouts need to be loaded in another layout only when required. Such layouts are the ones which are loaded in the layout on demand. Loading views on demand increases the performance of the layout, as the views are not present in the layout beforehand.
Hence, there is no processing of those layouts involved. The performance of a layout is increased a lot more if the view that is included on demand is a complex view. Also, the view might not be required until a certain condition is met and it would be no use to include that view in the layout and hamper the performance. A few examples of such views are item details, progress bars, and display messages.
This technique of loading views on demand can be implemented by defining a ViewStub for complex and rarely used views. Define a ViewStub ViewStub is a lightweight view.
It has no dimensions and, hence, doesn’t draw anything on the layout. This view is very cheap to inflate and include in a view hierarchy. Each ViewStub needs to include the android:layout attribute to be included in the layout to inflate.
Instead of choosing to inflate views manually and add them to your view hierarchy at runtime, use ViewStub. Its ease of use comes in very handy while developing.
One point to be noted here is that it does not support the tag. The following ViewStub is for a translucent progress bar overlay. It should be visible only when the server call is to be made to fetch data: [ ] Performance Matters The layout specified by the ViewStub can be called, either by making it visible by calling setVisibility View. It is replaced by the inflated layout and the ID for the root view of that layout is the one specified by the android:inflatedId attribute of the ViewStub.
Improving scrolls and other elements in the app As seen earlier, an item of a list plays a very important part in the performance of a RecyclerView. If the item view is made as efficient as possible, then the list will scroll very smoothly; otherwise, there will always be a lag while scrolling the list. The list scroll will be hampered more if the item view is very complex.
Here, in the following section, we will concentrate on improving this smoothness of scrolls in the app by focusing on some other important aspects besides that. The key to smooth scrolling is to keep the application’s main thread free from heavy processing.
Any kind of network calls, disk access, and database access must not be performed on the main thread. Using a background thread The tasks performed on the Android device in the foreground are all called the tasks on the main thread. These include loading tasks and any kind of user action. If a heavy processing task is performed on the main thread, then there will definitely be lag on the device. All such tasks have to be performed in a background thread which does not affect the main thread but still performs the task in the background.
Once the background thread’s task is completed, it informs the main thread to perform an appropriate action with the result. Using a background thread allows the main thread to focus on drawing the UI. Android has a built-in class for performing tasks on the background thread.
It is called AsyncTask and provides a simple way to perform your work outside the main thread. AsyncTask automatically queues up all the execute requests and performs them serially. Holding view objects in a ViewHolder Calling the findViewById method frequently during the scrolling of RecyclerView, can slow down performance and scrolling.
This method looks up the elements after they are inflated and then updates them. This could be avoided by not repeatedly calling the method findViewById but, instead, using a ViewHolder. First, you need to create a class to hold all sets of views. Understanding network requests, computation and memory This chapter will highlight key areas of app performance, such as network requests, computational algorithms, and memory leak issues. These components play an important role in the performance of the app and can considerably reduce the speed of an app, if endto-end cases are not handled well.
What Is Continuous Integration? Introduction No matter how good you are at writing code, without proper knowledge of Integrated Development Environments IDEs , you will face many obstacles. Each chapter focuses on a specific topic, progressing from the basics of how to use the IDE to advanced topics such as writing plugins to extend the capabilities of the IDE. What This Book Covers This book not only covers features of Android Studio essential for developing Android apps but also touches on topics related to the whole development cycle.
How This Book Is Structured Each chapter focuses on a specific topic related to Android Studio or an accompanying tool by explaining why it is needed and how it is used or configured. Some chapters provide code samples to demonstrate the use case or provide an example for the topic.
Expert android studio pdf free free
Replace method with method object What is the issue? The new project structure was very different because of the changes introduced by IntelliJ and Gradle. This will show the list of devices. Once the hierarchy viewer draws the layouts, it analyzes it and shows the performance of each layout using traffic lights. This book is the summary of the lessons we learned walking unaided on this difficult path.
Expert android studio pdf free free
Click here to know how to put your classifieds as VIP. Sea on foot. Terrace with Kitchenette microwave, toaster, kettle ,minibar,t.
Can accommodate four peoples 2 double beds. Situated in full town center close to restaurants, Each piece is handmade and unique, and cannot be exactly replicated. Slight variation may occur compared to the pictures. Follow me finding. Earrings purchased are strictly non-exchangeable and non-refundable. Artists Premium is an artistic and event agency specializing in artistic production and organization of shows.
Our agency has a catalog of music bands and professional artists from authentic gospel in the African American style, reggae, jazz, soul, Pop, dance Gospel choir for concerts, weddings, and other events June 09, You are organizing an event and you want to listen to the real gospel?
Afro-American gospel: authentic gospel? You are at the right place! Your Gospel Team is a gospel choir, the first one in Switzerland, specialized in the animation of the weddings, concerts, The machine is in good working order.
Detailed photos available on request. Perhaps you’d like to talk Very beautiful house “le Clos du chat tambour”, of m2 with basement, for sale on the Alabaster coast in Seine Maritime This house with a garden of m2, benefits from an exceptional location, quiet, 3km from the sea and 7 km from the city center Sell a living room coffee table made of exotic solid wood.
This semi-precious wooden coffee table “Courbaril” was brought back from French Guiana in It is in very good condition and very rare, not to say not to be found in metropolitan France and even We also do tutoring from CP primary to baccalaureat’s grade. We remain at your disposal. Guadeloupe Scribe Business Administration is a leading young business in marketing, communication and press relation at your services. With a past experience in graphic design proficiency, the team is waiting to boost your business on the market undoubtedly.
Our services Business bilingual secretary available to all types of businesses – Special business package November 16, Whatever your need in getting your projet done, or documents, we are experienced enough to provide you with the business communication level suitable to your need. French mother tong and proficient in english for business we are the one skilled solution at This event is unique in our department. On this occasion, professional and Reunion Island Ideal for sporty, adventurous bon vivants.
Wake up with the glow of the first rays of the sun over the mangrove forest. First a hearty breakfast with a view of the islands Nosy Carry out your projects in complete safety June 17, For all your credit or financing needs, we offer our services.
Reliable and very secure with a good interest rate. The property is about 12 minutes drive from Bought 15th October at Conforma, guaranteed for 2 years. Selling because we are moving. No delivery available. To be collected in Lamentin. To be collected in Lamentin Table
Expert android studio pdf free free.List of PDF software
What code needs to be refactored? Are your app screenshots nailing it? Summary Index [ vi ] Preface Introduction The book deep dives into understanding the design, develop, and distribute mechanism of building restaurant discovery app features that can be served “hot” to the end users. Building for performance is one of the aspects of a good app, and we have it covered in this book.
We will wrap up the book with how to publish to the Google Play Store. What this book covers Chapter 1, Understanding Gradle, teaches developers how to prepare Android Studio and its components for development. The developers will use Android Nougat 7. Chapter 2, Exploring Android Studio Developer Tools, explains that over the years, Android Studio has received a lot of productivity updates.
This chapter highlights how in-house tools will get the best of productivity while building restaurant discovery app features. Understanding support library will offer a number of features that are not built into the framework. Using support libraries will provide backward compatibility with the previous versions, providing some useful UI element support. Chapter 5, Material Design, explains that material design is almost over two years old now. Understanding design principles and implementing them in the key features of the restaurant discovery app are covered in this chapter.
This calls for a strong architecture planout. Chapter 8, Decision making, focuses on which is the development architecture followed while developing food discovery app and reasoning for the same. Chapter 9, Performance Matters, we will discussed how performance, impacts the app quality, followed by in ways by which we can target different elements of app performance such as UI, and resources such as the battery. We also discussed the tools that we can use to improve the app performance.
Chapter 10, Building Restaurant finder, in this we will understand the core techniques of coding the different components and screens of the Zomato app by yourself. After reading these topics, you understood what are the components required to develop certain sections on a screen.
Once you get a hold of these components, they can be reused in other screens with similar requirements. Chapter 11, Backend Service, looks at the development life cycle as having three different phases: development, testing, and distribution. The first of these is building an app and having the stuff you need to develop and support the app, which we have done in the earlier chapters. The firebase will allow us to have the backend in place.
It also sports Cloud Messaging, which lets you deliver messages and notifications reliably at no cost. Firebase Test Lab for Android enables developers to catch bugs before ship. Chapter 13, Grow Up, says that Admob supports a number of engaging formats, including video, natics, and interstitial ads.
This chapter will help developers understand ads, Firebase dynamic links, and app indexing. Chapter 14, Testing, assists developers in testing the entire app flow and improving the tests of the app. It will also highlight the best practices for testing and supported tools.
Chapter 15, Preparing for Google Play, focuses on how to prepare the store listing for the app. Chapter 16, Understanding App Store Analytics for Optimization, helps understand industry- followed best practices for App Store optimization.
Conventions In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning. Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: Here, jsouza is the user John Souza’s uid.
Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: “Firebase is a cloud based backend-as-a-service BaaS service provided by Google that provides a structural way to save your data very efficiently and also retrieve it at much faster speeds. Tips and tricks appear like this.
Reader feedback Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply email [email protected] , and mention the book’s title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www. Customer support Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase. You can download the code files by following these steps: 1. Log in or register to our website using your email address and password. Enter the name of the book in the Search box.
Select the book for which you’re looking to download the code files. Choose from the drop-down menu where you purchased this book from. Click on Code Download. Check them out! The color images will help you better understand the changes in the output. If you find a mistake in one of our books-maybe a mistake in the text or the codewe would be grateful if you could report this to us.
By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title. The required information will appear under the Errata section. Piracy Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy. Please contact us at [email protected] with a link to the suspected pirated material. We appreciate your help in protecting our authors and our ability to bring you valuable content. Questions If you have a problem with any aspect of this book, you can contact us at [email protected] , and we will do our best to address the problem.
They wanted to ensure that it becomes easier for developers to reuse code and also help them create build variants with ease. In this chapter, we will discuss: Setting up Gradle in Android Studio Dependent libraries to be used in Android Studio, including Identifiers If you have been using Eclipse, it’s likely that some of you won’t know of any alternative to the default APK generation technique within the IDE.
But, as such as alternative, you can do this using the command line. The Android build system compiles app resources and source code, and packages them into APKs that you can test, deploy, sign, and distribute. Gradle was designed keeping in mind the support for multi-project builds which grow to be quite a large size, and it supports incremental builds.
Gradle does this by understanding which parts of the build tree are up to date. Understanding the Gradle System This ensures that tasks dependent on those parts will not be re-executed.
Gradle can automate the building, testing, publishing, deployment, and more of software packages or other types of projects. Using the combination of the power and flexibility of ANT and the dependency management and conventions of Maven, Gradle helps to build in a more effective manner. First, let’s get familiarized with the Gradle environment inside Android Studio. To do that we should first create a new Android Project. I assume you have Android Studio installed by now.
Just click Finish when done: [ 11 ] Understanding the Gradle System When the project load is complete, just change the view structure to Project. You may leave it at Project Files by default: [ 12 ] Understanding the Gradle System Once this is done open the build. Here you will see the libraries that are compiled in the project: We have completed the launch of a blank project and we now should understand the basic setup of the same.
In the next section, we will talk about adding Gradle to this app. Adding Gradle to your app You can Gradle build script dependency to your app in the following way: Open the file from your app module.
Here are a few pointers to make note of: com. We will be using several libraries in our App. In the next section, we will see how to add new Gradle Libraries. Adding a new Gradle library Making Android Development more awesome, Gradle allows us to incorporate libraries in to Android Studio in different ways. Using these, developers can easily include their libraries using Gradle dependencies.
In this section we will discuss the following techniques: Adding a Gradle identifier Adding as a module Adding a Gradle identifier To add a new Gradle library, find the Gradle identifier for the third party library, and add it to the dependencies list. To sync your project files, click Sync Now as seen in the following figure in the notification bar this appears when you make a change , or click Sync Project from the menu bar.
If Android Studio notices any errors with your configuration–for example, if your code uses API features that are only available in an API level higher than your compileSdkVersion– the Messages window appears to describe the issue: Next, we will discuss how libraries can be added using a module.
To add the module: 1. First, place the library code in any folder of your choice 2. Then, you need to Import the library as a module in your app. The figure below shows the steps to add the library as a Module: This will open a new window where you need to select the library that you have saved to the directory. When you have selected the directory, click on Done.
This will import the external library into your project. As an example, I have added the module crop image to my project, which appears in my project folder. To do this, right click on the module that has been added and click on the Open Module Settings option: It will open a new window with your app module and library module in the list.
Choose you app module, and then select the dependency list. Select it and click OK: This will build the Gradle and add the module to the build. Alternatively, you can also define the dependencies of a project in the root build. In this case, we won’t be focusing on these points. Summary We started the chapter by looking at what Gradle is and how it is important in project development. We briefly looked at the Android Studio setup and how it can help in building the system along with Gradle.
After the introduction, we talked about how developers can set up Gradle in Android Studio. We also created a new project in Android and discussed how Gradle libraries can be added to the project.
To make these trade-offs, it’s important to know what the consumer wants. Now that we know how to use Gradle, in this chapter we will discuss some of the tools that provide help in building apps and also help in debugging and performance tooling. Gradle, by default, builds a single APK, no matter what libraries you include. This compiled and packaged file includes all of the application’s code.
Exploring Android Studio Developer Tools The library, within itself, comprises multiple copies of the same native code, optimized for the different architecture. A developer can easily run the command unzip. APK to understand the content of an APK: When your app, and the libraries it references, reaches a specific threshold, you encounter build errors that point to the app’s limit of the Android App Build Architecture.
The most recent Android build system displays an error, trouble writing output: Too many field references: ; max is You may try using –multi-dex option. Looking closely at the log, the number has a significant reason for appearing. This number represents the total number of references that can be invoked by the code within a single Dalvik Executable dex bytecode file. Both these error conditions display a common number: This number is significant in that it represents the total number of references that can be invoked by the code within a single dex bytecode file.
If you have built an Android app and received this error, then congratulations, you have a lot of code! Memory space on the phone is a competitive area and to make it worse, if users spot the large APK size they may well decide not to bother. Ensure that your app utilizes memory in a way appropriate for making users download and retain the app.
The smaller you make your APK, the more likely it is for the user to at least download the app in the first instance. Hence, the actions that need to be performed should be followed skillfully using some tools like APK Analyser, before the build is shipped. This tool helps to understand the contents and the sizes of the different components in your APK. With the help of this tool, you can reduce the size of your APK, by identifying the raw file size and estimated download size of each component that combine, to make up your APK.
Follow this step by selecting the APK you want to take a closer look at. The tool will then output in the main Android Studio window, so that you can explore the various components that make up the APK. Using this information, you can nail down the areas where you think there’s a loss of some excess bytes.
You need to understand the contents and sizes of different components in your APK, avoid 64K referenced method limit issues with your dex files, diagnose ProGuard configuration issues, view the merged AndroidManifest. This feature can help you reduce your APK size you’ll see both the raw file size as well as the download size of the various components. Understanding basic battery drain Earlier editions of Android OS used to run on Dalvik Runtime, which means apps used to compile at execution time.
Post-Lollipop edition, Android has switched to Android runtime ART , which means the apps are compiled beforehand, ensuring they are launched faster. ART, as the runtime, executes the Dalvik Executable format and dex bytecode specification.
Apart from the launch, the entire consumer experience using the app is essential for app retention. One important feature is the battery – a dear feature of the phone. An app which is greedy for power often finds itself in the position of either being uninstalled or lower rated when reviewed on the Google Play Store listing. Take a look at some of the most popular apps on the Store, including Facebook, which has had consistently bad reviews that quote battery drain as one of the top sources of user dissatisfaction.
If your app has the reputation of being a battery hog, that might incur a loss of potential users that could otherwise be using the app. Android developers usually neglect the way that their app could impact the battery life of the smartphone. Not that it needs deeper insights in embedded systems, but a few tips can help you to appreciate the impact of an app on battery life.
If your app is one of the top drainers of the battery in the device, what’s the best way to figure it out? The battery setting menu has an information resource to diagnose battery drain issues caused by mobile apps. Simply heading to Settings Battery will provide the user with the necessary information in a graphical format, comparing consumption against time.
The records are maintained since the last full charge status. There is also an interesting statistical overview of the applications that have contributed to battery drain: Clicking on the graphs opens an extended section that shows how much time your device has spent in various cellular states.
The different color patterns such as green, yellow, and orange indicate the signal strength. This might be the result of a Wakelock or alarm that uses the device resources when the user might not be actively using the device. If this is frequently seen, it calls for some optimization. We will be talking about the Wakelocks and their impacts during the performance section of this book. Batterystats and Battery Historian The Android Settings menu options provide high level measurements of battery drain.
However, to gain more insight into battery consuming apps, there are some tools that can be useful. Tools such as Batterystats and Battery Historian come in handy. Batterystats collects battery data from your device, and Battery Historian converts that data into a HTML visualization that helps you understand power consumption graphically.
Batterystats, was introduced in KitKat, but Lollipop brought a large dataset for the users which included data about every Wakelock action on the device. Please reset the data and enable full Wakelock reporting to receive comprehensive information including how the device utilizes the battery, along with details about all the running processes.
Here are some of the commands you can run after connecting your device: adb shell dumpsys batterystats –reset Resets all of the data in the Battery Settings menu before generating the new dataset adb shell dumpsys batterystats –enable full-wake-history Enables full Wakelock reporting adb shell dumpsys batterystats –charged Enables you to receive the data since the phone was last fully charged [ 24 ] Exploring Android Studio Developer Tools If you wish to know what a Batterystats System Dump looks like, you can run the command using the command line interface in Android Studio.
Take a look at the sample as follows: We will be talking more about what each of these components mean during performance in Chapter 15, Understanding App Store Analytics for Optimization later in the book, where we will cover in detail how each of these elements help users to optimize the Android App for better performance.
This was launched with new reports completely rewritten in GO. This tool provides extensive information that helps you drill down into battery data for your specific application.
To run the latest edition of Battery Historian, you will need Android Devices with versions later than Android 5. Please follow the installation guide given on the link above to complete the setup.
You can either save the file or check the output right from the terminal window. Exploring each component, the following are the important keywords of the stats: Battery History: This shows the time series of various power-relevant events, such as the screen being on, radio signals and app launch.
You can also get details of each one of these using the Battery Historian graph, which we will discuss in the next section. Some of the statistics include, but are not limited to: phone signal levels, screen brightness, signal scanning time, time on battery, time on battery screen off, Wi-Fi signal levels, Wi-Fi idle time, and Wi-Fi Power drain in mAh.
Estimated power use mAh by UID and peripheral: This is an extremely rough estimate and its use should avoid consideration as an experiment data. Per-app mobile ms per packet: Shows the Radio-awake-time divided by packets sent – which means, since an efficient app transfers all its traffic in batches, the lower the value, the better it is for the app’s performance. All partial wake locks: All app-held Wakelocks, by aggregate duration and count.
Batterystats collects battery data from your device. Using these Batterystats, the battery usage could be discovered using a Battery Historian, which would create a HTML file for viewing the Batterystats results in a browser for user viewing. A graphical representation from Battery Historian of the live Zomato App is shown in the following screenshot: [ 26 ] Exploring Android Studio Developer Tools Using the Battery Historian, important statistics can be drawn upon: It shows you the processes from the device that consume your battery.
Here, you could compare the battery usage for each process. It also shows you the tasks from an app that consume more of the battery, so that you can take necessary action on them. The preceding graph representation shows the readings, based on various categories of the Historian. A few of the major categories to look out for, and to analyze regarding the battery consumption for a device, are listed as follows: Battery level: This shows the battery level of the device when it was recorded.
It helps you determine how fast the device battery drains out. Screen: Shows whether the screen was ON. Top: It shows the application that consumes the most battery usage. Currently the Zomato App is at the top, as the records have been taken, resetting the battery usage and using only the Zomato App.
The usual process of the App is to wake up, do a small amount of work, and then go back to sleep. Waking up the app is very expensive to the battery. So if there are lot of bars showing up, it might be a problem. Running: This shows if the CPU is awake. Here, it should be awake at the times when you are doing some processing, and in sleep mode when not.
If it shows as running even if you are not performing any actions, it means there are background processes that are making your CPU do a lot of processing, and hence consuming the battery. Unzip the file to extract the Battery Historian folder. Find the historian. Connect your mobile device to your computer. On your computer, open a terminal window.
Change the directory path to the path where you have saved historian. Shut down your running adb server : adb kill-server 7. This will show the list of devices. If you don’t see any devices, make sure your phone is connected and USB Debugging is turned on, and then kill and restart adb. Resetting erases old battery collection data; otherwise, the output will be huge. Disconnect your device from your computer so that you are only drawing current from the device’s battery.
Use the app for a while, until it gathers a sufficient amount of data for your use. Reconnect your phone. Dump all battery data. Open the batterystats. The Battery Historian tool makes it simpler to dig into the data for one single process. As a developer, you can easily spot battery drain functions using this tool and work on its resolution.
In the next section, we will discuss the memory monitor tools. Managing the RAM is the most critical section in the Android app development process, as the physical memory is often constrained. The fundamental principle of memory management is to avoid a memory leak from your app. In Android Studio there is a tool we can use to check the memory usage in the App. To check this you could follow these steps: 1. Run your app on an Android device connected to an emulator.
Open the Android Monitor tab in Android Studio situated at the bottom window. Open the Monitor section within it, and you are there. Here you’ll be able to continuously check the memory usage of the app as and when the app is being used. The following image shows the memory usage for an app: [ 29 ] Exploring Android Studio Developer Tools The preceding memory graph shows the memory used by a device against time.
This graph shows the memory usage in the app when any process is performed by the app, be it loading data over the network, displaying an image, rendering a view on the screen, or running a background task. There are two graphs being plotted at the same time here, one with the allocated memory that could be used by the device.
OutOfMemoryException error is the most common cause of unconventional crashing of an app due to memory leaks, and the Memory Monitor tool can help you to debug the same. Wondering what the various causes of memory increase are? In any app, the memory is bound to increase at various points of time as and when you use it. Do not panic if the memory keeps on increasing when you do some stuff in the app, like loading data over the network, displaying an image, rendering a view on the screen or running a background task.
It means that for whatever task you do in the app, for example displaying an image onto the screen, the app needs to allocate some amount of space in the RAM.
Now, this allocation is for one particular process. Similar allocations will also happen for other processes. These will increase the memory and, if not handled, may cause a memory leak in your App. For most of the Apps, Android has a Dalvik garbage collector, which takes care of the memory allocations and releases the memory when done.
This will help prevent memory leaks. By carefully understanding how your Android application handles memory operations, you can ensure that the app is running efficiently on memory contained devices.
Eventually, this will also lead to a reduction in out-of-memory crashes. Logcat displays messages in real time and also keeps a history so you can view older messages. Log Log Level Description Log. Error Tag and message are the string data-type. You can search for messages in the logcat by; Typing a character sequence in the search field Optionally selecting Regex if you want to use a regular expression search pattern The logcat will reflect the changes accordingly.
Apps without optimization can severely impact the battery life of a device. We’ve walked though in-depth analysis of battery drain in Android Apps. We also looked at Batterystats and the Historian tool to analyse battery usage patterns.
Additionally, we explored memory optimization to ensure the app runs smoothly and stays off the memory leaking track. These include smartphones, tablets, Smart Wears, smart TV’s, and even cars.
From just a mobile computing platform, Google has used the powers of Android to a great and deeper extent. Looking at the Android distribution, Android 4. Comparing smartphone OS global market shares from Q to Q, Android has grown massively from 1.
At this pace, we can expect M users by In this chapter, we will look at the Android Support Library features and how they assist us in the project.
The Android Support Library Supporting multiple devices can pose issues, particularly when users expect apps to function seamlessly on every device, in the same way. This expectation rises even when users know very well that there is a significant difference in the software and hardware of the phone. While Google releases, latest updates to Android, it is not necessarily true that all OEMs follow up on this update on their smartphone.
This leads to the fact that most of the users tend to use releases which are approximately 15 months old or older. Leap into the Android Support Library If that is held true, developers would have to compromise a lot in order to support most of their users, running several versions of Android. Fortunately, the Android team is aware of this and endeavors to provide consistent help for the developer in this regard.
This is a tricky issue, especially considering the consistency of the app feature that shouldn’t affect the architectural structure.
The Android Support Library is a collection of libraries, which are available on several API levels, that help developers to focus on the unique parts of their app, supporting new functionality and compatibility issues that might arise due to different versions running on different devices. Setting up Android Support Libraries in your development environment depends entirely on what features you want to use and what range of Android platform versions you are targeting with your application.
Please follow the steps given as follows to set up the Support Library files: 1. If you have opened the standalone SDK Manager, this option would be in the Extras section, as shown in the following image: 2. Here is the list of supported libraries: Support Library Description Gradle Dependency v4 compat library Provides compatibility wrappers for a com.
We will be using these primarily in our app. Here is the list of supported libraries: Support Library Description Gradle Dependency v7 appcompat library This will be one library that com. This library supports the Action Bar Design pattern. Moreover, it also includes support for material design user interface implementations.
This library depends on the v4 Support Library. This allows us to show up information in the form of cards, which can be supported on any device. Using this library adds support for the GridLayout class, which allows you to arrange UI elements using a grid styling. In short, it supports streaming and routing of media channels from one device to external devices. This is mainly used in music applications.
This library provides support for building apps that support multiple dex files. Apps that have references to more than methods would be required to use multidex configuration. The gradle dependency identifier for this library is as follows: com.
It has v8 renderscript library – which adds support for the RenderScript computation framework. It supports the FragmentCompat class and additional fragment support classes.
We followed this by discussing several libraries that can help developers to use libraries which can offer backward-compatible versions of new features. With automatic platform updates distributed as an APK on the Google Play Store, developers can easily receive the updates and more easily integrate Google features. This interface also allows you to obtain authorization from users to gain access to these services using the users’ credentials.
These services include Google Drive, Play Games and more. Since the library derives updates from Google Play, it does contain APIs that help you resolve any issues at runtime. Sometimes you may have come across apps that prompt you to update Google Play Services before proceeding. The service performs the desired action on your behalf.
Also, to include a specific dependency for your app, proceed to add specific services in your app’s build Gradle. The various services provided by Google Play Services could be included in an Android app using a Gradle path in the app’s build.
The default password for the debug keystore is android. Post this, you will able to see the fingerprint displayed onto the terminal. To make this possible, you need to register your Android app with the Google Cloud Console by providing your app’s package name and the SHA1 fingerprint of the keystore, using which you will sign the release APK. To register your Android app with Google Cloud Console, follow these simple steps: 1.
Click on Create project and enter the project name. Click Create. This will create a new project in your Google Developer Console. Since we have created the project, we will now enable the APIs that are required for the project. To enable the APIs, click on the library tab. Here you will see the list of all APIs that can be added to the app. First go to the library tab in the Google developer console. Next go to the Credentials. Here we will be creating an OAuth credential for the app so that the user can log in from the Android app.
Before we create a new credential, we have to fill in OAuth details of the app: [ 46 ] Google Play Services 4. After all of these details have been filled, go to the Credentials tab and click on Create credential: [ 47 ] Google Play Services 5. In our case, it is an Android app, so we would select Android: 6. Then you will see an option to add the app’s package name and signingcertificate fingerprint. Here you will see an option to select an app and enter the package name.
Fill in the details and click on Choose and configure services: [ 49 ] Google Play Services 9. At this screen, enable Google Sign In and enter the signing-certificate fingerprint. Then click on Generate configuration file: [ 50 ] Google Play Services You can now download the google-services. Now, add the dependency to your project-level build. Also, add this plugin in your app-level build. Finally, add the dependency into your app-level Gradle: Compile com. We have now completed the setup for Google Play Services for this app.
In the next section we will discuss the Android Architecture we would follow, along with discussion on the UI patterns for this app. After saving the API key, use the key in your app.
Now in your app, add the dependency in your app’s build. Save the file. After adding, save the AndroidManifest. Next, we discussed Google Sign up, followed by Google Maps.
Google has set design principles as guidelines to help developers work with material design for their apps. This principle sets up visual cues, motion, and interaction design across platforms and devices, making it a unified design belief.
In this section, we will cover how to incorporate material design into your app. Wireframing and tools to gather feedback Wireframing is a technique to plan out the high-level screen hierarchy for your application and display the forms that would be present in your app by providing some mode of navigation, to allow users to effectively traverse your app flow. Some apps have wireframes expressed in a tree structure, a graph, or a flowchart. The methods of wireframing could vary based on the type and magnitude of the app, but the standard patterns of wireframing remain the same.
Also, there are varieties of tools that could be used across different types of apps and different kinds of information that represent the types of things users interact with in your app.
Software engineers and data architects often use entity-relationship diagrams ERDs to describe an application’s information model. We will understand and learn the various techniques of wireframing in detail in this chapter. Material Design Understanding the wireframing process tangible and digital Before understanding the actual wireframing process, it will be nice to gather some initial information about things that would help draw some effective wireframes.
Once you understand what your app will do, the first step is to list the screens present on the app step by step.
We will wrap up the book with how to publish to the Google Play Store. All of the code is organized into folders. Each folder starts with a number followed by the application name. For example, Chapter Reactive Programming for Android [Video]. Android System Programming. Reactive Android Programming. Simply click on the link to claim your free PDF. Skip to content. Star This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Branches Tags. Could not load branches. Could not load tags. What This Book Covers This book not only covers features of Android Studio essential for developing Android apps but also touches on topics related to the whole development cycle.
How This Book Is Structured Each chapter focuses on a specific topic related to Android Studio or an accompanying tool by explaining why it is needed and how it is used or configured. Some chapters provide code samples to demonstrate the use case or provide an example for the topic. Creating an emulator for running your projects. Creating and working with modules. How to use live templates and refactoring.
How to build your projects and sign apks. Explanation of previews and tools for UI development. Managing external dependencies. How to use and organize assets. Interacting with UI, editor, and adding your actions.