Android programming pushing the limits

Android Programming. Pushing the Limits

Скачать книгу

О книге «Android Programming. Pushing the Limits»

Unleash the power of the Android OS and build the kinds of brilliant, innovative apps users love to use If you already know your way around the Android OS and can build a simple Android app in under an hour, this book is for you. If you’re itching to see just how far you can push it and discover what Android is really capable of, it’s for you. And if you’re ready to learn how to build advanced, intuitive, innovative apps that are a blast to use, this book is definitely for you. From custom views and advanced multi-touch gestures, to integrating online web services and exploiting the latest geofencing and activity recognition features, ace Android developer, Erik Hellman, delivers expert tips, tricks and little-known techniques for pushing the Android envelope so you can: Optimize your components for the smoothest user experience possible Create your own custom Views Push the boundaries of the Android SDK Master Android Studio and Gradle Make optimal use of the Android audio, video and graphics APIs Program in Text-To-Speech and Speech Recognition Make the most of the new Android maps and location API Use Android connectivity technologies to communicate with remote devices Perform background processing Use Android cryptography APIs Find and safely use hidden Android APIs Cloud-enable your applications with Google Play Services Distribute and sell your applications on Google Play Store Learn how to unleash the power of Android and transform your apps from good to great in Android Programming: Pushing the Limits.

На нашем сайте можно скачать книгу «Android Programming. Pushing the Limits» в формате pdf или читать онлайн. Здесь так же можно перед прочтением обратиться к отзывам читателей, уже знакомых с книгой, и узнать их мнение. В интернет-магазине нашего партнера вы можете купить и прочитать книгу в бумажном варианте.

Источник

Android Programming: Pushing the Limits

English | 2014 | ISBN: 978-1-118-71730-1 | 434 Pages | PDF | 14 MB

Unleash the power of the Android OS and build the kinds of brilliant, innovative apps users love to use
If you already know your way around the Android OS and can build a simple Android app in under an hour, this book is for you. If you re itching to see just how far you can push it and discover what Android is really capable of, it s for you. And if you re ready to learn how to build advanced, intuitive, innovative apps that are a blast to use, this book is definitely for you.
From custom views and advanced multi-touch gestures, to integrating online web services and exploiting the latest geofencing and activity recognition features, ace Android developer, Erik Hellman, delivers expert tips, tricks and little-known techniques for pushing the Android envelope so you can: Optimize your components for the smoothest user experience possible Create your own custom Views Push the boundaries of the Android SDK Master Android Studio and Gradle Make optimal use of the Android audio, video and graphics APIs Program in Text-To-Speech and Speech Recognition Make the most of the new Android maps and location API Use Android connectivity technologies to communicate with remote devices Perform background processing Use Android cryptography APIs Find and safely use hidden Android APIs Cloud-enable your applications with Google Play Services Distribute and sell your applications on Google Play Store
Learn how to unleash the power of Android and transform your apps from good to great in Android Programming: Pushing the Limits.

Источник

Android Programming: Pushing the Limits

Unleash the power of the Android OS and build the kinds of brilliant, innovative apps users love to use

If you already know your way around the Android OS and can build a simple Android app in under an hour, this book is for you. If you’re itching to see just how far you can push it and discover what Android is really capable of, it’s for you. And if you’re ready to learn how to build advanced, intuitive, innovative apps that are a blast to use, this book is definitely for you.

Читайте также:  Read qr code android

From custom views and advanced multi-touch gestures, to integrating online web services and exploiting the latest geofencing and activity recognition features, ace Android developer, Erik Hellman, delivers expert tips, tricks and little-known techniques for pushing the Android envelope so you can:

  • Optimize your components for the smoothest user experience possible
  • Create your own custom Views
  • Push the boundaries of the Android SDK
  • Master Android Studio and Gradle
  • Make optimal use of the Android audio, video and graphics APIs
  • Program in Text-To-Speech and Speech Recognition
  • Make the most of the new Android maps and location API
  • Use Android connectivity technologies to communicate with remote devices
  • Perform background processing
  • Use Android cryptography APIs
  • Find and safely use hidden Android APIs
  • Cloud-enable your applications with Google Play Services
  • Distribute and sell your applications on Google Play Store

Learn how to unleash the power of Android and transform your apps from good to great in Android Programming: Pushing the Limits.

Источник

Android programming pushing the limits

Copy raw contents

chapter 1: Fine-Tuning Your Development Environment

$ android update sdk —no-ui # update sdk

The adb (Android Debug Bridge) Tool

$ adb logcat MyActivity:* *:S # filter log

#executes the Monkey tool on an application with the specific

and injects as many random events as specified by . emulator -list-avds @ «>

connect device via wifi

The Android SDK comes with a number of ready-to-use library projects that can be found under extras/ google in the SDK folder. More specifically, you can find library projects for the Play Services, APK extensions, In-app Billing and Licensing features.

chapter 2: Efficient Java Code for Android

JIT compilation, also known as dynamic translation, takes the byte-code and translates it into native code prior to execution

Another difference between the Java SE VM and the Dalvik VM is that the latter is optimized for running in multiple instances on the same machine.

The only problem with AsyncTask is that you can use each instance of this class only once, which means that you have to call new MyAsyncTask() every time you want to perform this operation.

it is not suitable for operations that you perform frequently because you would quickly gather up objects that need to be garbage collected and eventually cause your application’s UI to stutter.

In addition, you cannot schedule the time for the execution of this operation or perform the operation at a certain interval. The AsyncTask class is suitable for things like file downloads or similar situations that will happen relatively infrequently or by user interaction.

Handler(more powerful than AsyncTask)

This class allows you to schedule operations with exact precision, and you can reuse it as many times as you want. The thread that executes the operations loops until you explicitly terminate it;

two types of handle creation

Chapter 3: Components, Manifests, and Resources

The three core concepts of any Android application are the components, the manifest, and the resources.

  • Activity # with ui
  • Services # background task, doesnt constraint by Activity
  • BroadcastReceivers # listen for system events
  • ContentProviders # store application data
  • Application #

Android Data storage:

  • file
  • ContentProvider
  • sqlite
  • SharedPreferences

You can consider the Application component as a top-level component that’s created before Activities, Services, and BroadcastReceivers.

You can always retrieve a reference to the Application component through the method Context.getApplication(). Because all Android apps will have one and only one instance of this component, you can use it to share variables and communicate across the other components within your app.

The Manifest Element

The android:sharedUserId and android:sharedUserLabel are the Linux user ID and name that your application will run on. By default, these are assigned by the system, but if you set them to the same value for all the applications you publish using the certificate, you can access the same data and even share the process of these applications. If you’re building a suite of applications or if you have a free and a paid version, this can be very helpful.

Google Play Filter: pass

Читайте также:  Управление экраном android adb

The Application Element: be sure set label and description, android:backupAgent

set android:enabled=”false”, then set it back when user finish certain configuration.

Explicit Intents contain information about the package and the name of the component,

Implicit Intent resolution depends on three factors: the action of the Intent, the data URI and type, and the category.

All components in Android are accessed using Intents.

Resource vs Assets

All resources belong to a certain type (such as layout, drawable, and so on), whereas assets are simply generic files stored inside your application.

always put a default resource, or you app may crash

However, because the assets directory supports subfolders, in some situations, you may still want to use assets instead of resources.

Chapter 4: Android User Experience and Interface Design

When developing Android applications you have a large set of ready-made UI elements, called widgets, in the Android SDK that you can use.

Dimensions and Sizes:

One dp is roughly equal to one physical pixel on a 160 dpi screen.

You should specify all dimensions in your UI using the dp unit, with one exception: When specifying font sizes, use the unit sp, which is based on the dp unit but also scaled according to the users’ preferences for font sizes.

48 dp == 48 px on MDPI

The short answer is “the 48-dp rhythm.” Basically, 48 dp translates to about 9 mm on the screen, which is within the suitable range for objects on a touchscreen that users need to interact with using their fingers.

Four standard font size: These are micro (12 sp), small (14 sp), medium (18 sp), and large (22 sp).

Chapter 5: Android User Interface Operations

Designing Custom Views (自定组件)

Chapter 6: Services and Background Tasks

Simplified, a Service is either started or stopped, which makes it much easier to handle than the more complicated lifecycle of an Activity. All you really need to remember is to create expensive objects in onCreate() and do all cleanup in onDestroy()

onCreate & onDestroy 仍然在主线程执行, 可以用 AsyncTask 来处理这一部分

Communicating with Services

The drawback to this solution is that you’re limited to what an Intent can carry. Also, you cannot use this solution for multiple, fast updates between the IntentService and your Activity, such as progress updates, because doing so will choke the system.

Local bind service with callback

Chapter 7: Android IPC

two ways of IPC:

  • the Binder IPC (Inter-Process Communication).
  • existing solution in the Linux kernel named dbu

The Binder isn’t just used by Services, it also handles all communication between Android components and the Android system.

why service dont block main thread:

Communication using the Binder follows the client-server model. Clients use a client-side proxy to handle the communication with the kernel driver. On the server-side, the Binder framework maintains a number of Binder threads. The kernel driver delivers the messages from the client-side proxy to the receiving object using one of the Binder threads on the server-side. This is important to remember because when you receive calls to a Service through the Binder, they will not be executed on the main thread of your application. That way, a client to a remote Service cannot block the Service application’s main thread.

Binder client vs Binder Server: client call IBinder.transact(), server will receive data from Binder.onTransact()

Clients that want to communicate with a Service or other component query the ServiceManager, implicitly through the Intent resolution, to receive the Binder address.

They are used as simple data containers for the data you want to include in the transaction.

you can create a Parcel by implement Parcelable interface

Another feature of the Binder in Android is that it allows clients to be notified when a Service is terminated

Chapter 8: Mastering BroadcastReceivers and Configuration Changes

Читайте также:  Cisco anyconnect android импорт сертификата

create a BroadcastReceiver:

BroadcastReceivers can also be registered programmatically within Activities and Services. Some broadcast Intents can only be registered programmatically, and some only work if you declare them in your manifest.

register by: xml mainifest

programmatically: dynamic, register only your acitivty is running(thus consume less resource), remmber to unregister it onPause

If you want to send and receive broadcast only within your own application’s process, consider using the LocalBroadcastManager instead of the more generic Context.sendBroadcast() method. This approach is more efficient because no cross-process management is included and you don’t have to consider the security issues normally involved with broadcasts.

Normal and Ordered Broadcasts:

Normal:没有顺序 sticky broadcast: nomarl braodcast 的一个变种, 当 Intent(消息)被发送成功之后, 消息不会立即消失, 方便下个组件监听这个事件仍会得到此分类的通知 directed broadcasts: 可以指定获得的组件名称

Ordered: 有顺序, 任何一个环节可以阻止通知的下沉

network, screen lock, configuration.

Chapter 9: Data Storage and Serialization Techniques

Chapter 10: Writing Automated Tests

Using TDD involves a number of tools and techniques. First, you need a unit-testing framework for writing the automated tests. This framework, which is included in the Android APIs, is the main focus of this chapter. Second, you need a continuous integration and build server. This server automatically builds your application and performs all the automated tests for every change in the code. Finally, you need a code-coverage tool that tells you how much of the application’s code is really being tested.

AndroidTestCase: without android component life cycle

Testing Activities: ActivityUnitTestCase ActivityInstrumentationTestCase2

Chapter 12: Secure Android Applications

Signatures and Keys:

uring normal development, you will use the auto-generated debug key for signing your application (which is done automatically by the Gradle build system or the IDE). When you publish your application on the Google Play Store, be sure to use a unique key that you generate manually using the keytool application.

the only reasons for using the same key for multiple applications is when the applications need to access each other’s data directly, or you have defined permissions with the protection level signature.

When you generate a new key, the keytool asks you for a password. If you don’t provide a password, anyone with access to the keystore file can create a properly signed application. Thus it’s highly recommended that you use a unique password for each keystore file.

Android Permissions: normal: 用户会接受到通知 dangeous: 用户会在安装时提示 signature: 需要同一个证书签名 signatureOrSystem and system: 手机制造商的权限,一般程序无法达到

Chapter 14: Native Code and JNI

Chapter 15: The Hidden Android APIs

Chapter 17: Networking, Web Service, and Remote APIs

Never perform network calls on the main thread. Always do networking on Android from a Service and avoid performing network calls from within an Activity (exception is Auth2)

I recommend using either a callback interface or the LocalBroadcastManager to communicate network results between the Activity and the Service. Another way is to store the results from a network call directly into a ContentProvider and let the provider notify registered clients about the changes to any data,

Volley (vs OkHttp?)

OkHttp and SPDY If you choose to use SPDY as your communication protocol, I recommend that you choose the third-party library called OkHttp, which is developed by Square, Inc.

When you create a new instance of the OkHttpClient, it will set up everything you need, such as connection polling and response cache

If you need to transmit a large file between the client and server, stick to standard HTTP instead.

Facebook SDK for Android:

Finding Online Web Services and APIs:

Often, it may be cheaper to pay for an existing service than try to implement one from scratch, unless that’s your core business.

Server Side Notifcation:

  • Power Efficient Network Polling:
  • Server-Side Push (through: like SMS, or it can be a regular TCP socket with a long keep-alive.)
  • Web Sockets for Server-Side Push and you need to adjust the timeout on the socket on both the server and the client for this method to be efficient.

Designing Custom Views

The Manifest Element

todos: how to write a android module You can set up a library project from the Android Studio IDE. Simply create a new module and choose Android Library as the module type.

Источник

Оцените статью