Book Image

Mastering Android Development with Kotlin

By : Miloš Vasić
Book Image

Mastering Android Development with Kotlin

By: Miloš Vasić

Overview of this book

Kotlin is a programming language intended to be a better Java, and it's designed to be usable and readable across large teams with different levels of knowledge. As a language, it helps developers build amazing Android applications in an easy and effective way. This book begins by giving you a strong grasp of Kotlin's features in the context of Android development and its APIs. Moving on, you'll take steps towards building stunning applications for Android. The book will show you how to set up the environment, and the difficulty level will grow steadily with the applications covered in the upcoming chapters. Later on, the book will introduce you to the Android Studio IDE, which plays an integral role in Android development. We'll use Kotlin's basic programming concepts such as functions, lambdas, properties, object-oriented code, safety aspects, type parameterization, testing, and concurrency, which will guide you through writing Kotlin code in production. We'll also show you how to integrate Kotlin into any existing Android project.
Table of Contents (24 chapters)
Title Page
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Other important tools


We will cover some other tools you will need in everyday Android development.

Let's start with the following:

  • adb dumpsys: To get information about a system and running an application, use the adb dumpsys command. To get a memory status, execute the following command--adb shell dumpsys meminfo <package.name>.

Next important tool is as follows:

  • adb shell procrank: The adb shell procrank lists all the applications for you in the order of their memory consumption. This command does not work on live devices; you connect only with emulators. For the same purpose, you can use--adb shell dumpsys meminfo.
  • For battery consumption, you can use--adb shell dumpsys batterystats--charged <package-name>.
  • Next important tool is Systrace. To analyze performance of your application by capturing and displaying execution times, you will use this command.

When you have problems with application glitches, Systrace tool comes as a powerful ally!

It does not work with Android SDK Tools less than 20! To use it, you must have Python installed and configured.

Let's try it!

To access it from UI, open Android Device Monitor in Android Studio and then choose Monitor:

Sometimes, it can be easier to access it from the terminal (command line):

Note

The Systrace tool has different command-line options, depending on the Android version running on your device.

Let's take a look at some examples:

General usage:

$ python systrace.py [options] [category1] [category2] ... [categoryN]
  • Android 4.3 and up:
$ python systrace.py --time=15 -o my_trace_001.html 
        sched gfx  view wm
  • Android 4.2 and lower options:
$ python systrace.py --set-tags gfx,view,wm$ adb shell stop$ adb shell start$ python systrace.py --disk --time=15 -o my_trace_001.html

The last important tool we want to present is sdkmanager. It allows you to view, install, update, and uninstall packages for the Android SDK. It is located in android_sdk/tools/bin/.

Let's take a look at some common examples of use:

Listing installed and available packages:

sdkmanager --list [options]
  • Installing packages:
sdkmanager packages [options]

You can send packages you got from --list command.

  • Uninstalling:
sdkmanager --uninstall packages [options]
  • Updating:
sdkmanager --update [options]

There are also some other tools you can use in Android, but we only showed the most important ones.