Sie sind auf Seite 1von 29

How to Build an App:

ANDROID EDITION

Table of Contents
How to Build an App: Android Edition
1

Whats All the Excitement About?

Step 1: Decide What New Thing You Want to Do

Step 2: Dene Your MVP

Step 3: Design Your App

12

Step 4: Set up Your Android Development Environment

16

Step 5: Developing Your App

HOW TO BUILD AN APP: ANDROID EDITION


Whats All the Excitement About?

NFC is useful for actions like automated

Its never been easier or quicker to build

store checkout, inventory counting,

and distribute an application to millions

contact information exchange, and

of devices and get paid, especially when

oering special deals to customers in a

you tap into Androids market leading

specic store aisle.

features.

We are living in the Post-PC era. That


sentence in quotes comes up over
14,000 times in a Google search. So what
are so many people writing about? They
are writing about a time when many
computing tasks such as staying in
touch with friends, doing online
research, shopping, and playing games

Android also oers features not found on

no longer require a laptop or desktop

other mobile platforms like iOS or

computer. Not only can these activities

Windows Phone that make development

now be done on the go with a smart-

easier. Two good examples are the

phone or tablet, but they can also be

AccountManager system and the

done in new ways that enrich the

AccountAuthenticatorActivity base class,

experience.

both of which streamline the process of


setting up custom accounts such as to

Android devices are a great example.

register and authenticate user IDs and

Many are location-aware; many have

passwords. Android also oers market-

accelerometers that know when the

leading capabilities for letting applica-

phone is moving, in which direction and

tions on the same device invoke each

how fast; and many include NFC (Near

others services. That way a developer is

Field Communications), a technology

spared the work of implementing and

that enables easy communications (such

replicating an already-existing service.

as by tapping) between two devices or


between a device and a passive tag.

Besides its technical advantages, Android


also oers developers major business
opportunities.

HOW TO BUILD AN APP: ANDROID EDITION


According to Google, there were over 1

service that users and applications share

million apps available on Google Play as

via the Internet. A cloud may be private

of July 1013, with over 50 Billion

i.e., the services belong to an

downloads. According to IDC, Android

organization for the benet of its

accounted for 79.3% of worldwide

employees and business partners. Or a

smartphone shipments in Q2 of 2013

cloud may be public i.e., a company

in a market that did not exist until 2008.

(such as Amazon or Kinvey) owns the


services, which it oers commercially to
the public, including app developers. In

Android accounted for 79.3%

the Android space, Cloud services


typically function as an apps backend.

of worldwide smartphone
shipments in Q2 of 2013

They may do computational tasks


considered too heavy for a phone.

They might also store, secure and share

Two recent developments in particular

where users need to access the current

have sparked this growth: the Android

state of play.

data among multiple users on dierent


phones. A good example is a game app

ecosystem and the Cloud. The ecosystem consists of resources like Android

If you are a developer and want to build

Development Tools (to be discussed

your own backend, you certainly can do

later) and distribution platforms (like

that. Whether you want to or not

Google Play) that accelerate app

probably depends on whether your

development and marketing. These

backend will set your app apart in the

platforms remove the friction involved

eyes of your potential customer. If its a

in distributing and selling traditional

service thats fairly typical across lots of

desktop applications. Theres no physical

apps like user authentication or a

packaging, no inventory stocking, and

shopping cart then the answer is

much less waiting for developers to get

probably no. You may be better o

paid. You simply register online, pay a

hooking into a commercial backend

nominal fee, upload the app and youre

provider via an API.

in business.

The Cloud is a general term meaning a

Then you can focus on what counts

Step 1
DECIDE WHAT NEW THING
YOU WANT TO DO

HOW TO BUILD AN APP: ANDROID EDITION


most a unique user experience and

just by tapping the two phones together.

application-specic functionality. That


brings us to the rst step in making an

Other app opportunities involve

app.

information sharing. A prime example of


that is Google Docs that lets dierent

Why do people buy apps? Why do they

users on dierent devices work on the

make them? The answer to both

same document (in the Cloud) coopera-

questions is that a successful app

tively. A similar opportunity is context

improves users lives in new ways

sharing such as when the user starts a

typically by taking advantage of features

movie on a smartphone, stops the

like location awareness and accelerom-

movie, and later picks up the action at

eters that are present in phones. A great

the very same point on a TV, PC, tablet,

example app is Google Now, which

or another smartphone.

Google describes as follows:


The key, again, is identifying a function
Google Now gets you just the right

that improves peoples lives. That

information at just the right time.

requires, rst, identifying the value to be

It tells you todays weather before you

provided, second, conceptualizing a core

start your day, how much trac to

function that provides that value and,

expect before you leave for work, when

third, researching the market to make

the next train will arrive as youre

sure there is nothing else out there that

standing on the platform, or your

already does what your app will do. The

favorite team's score while theyre


playing. And the best part? All of this

research part is easy since you can

happens automatically. Cards appear

probably nd out if a similar app already

throughout the day at the moment you

exists just by spending a few minutes on

need them.

Google Play.

The Google Maps API enables location

Does your app meet all three of these

awareness so apps can tailor the user

tests? Good, then lets proceed to the

experience based on location such as

next step.

by recommending stores or restaurants


in that area. As previously noted, NFC is
a feature that lets users easily exchange
data, such as photos or contact
information, with another NFC phone

Step 2
DEFINE YOUR MVP

HOW TO BUILD AN APP: ANDROID EDITION


Most unsuccessful apps fail for any of

It was enough to prove the convenience

three reasons:

and accuracy of using Google.

1. the app was a solution in

The same MVP approach drives the app

search of a problem (i.e., no real need

market today. With each app focused on

existed)

meeting a specic need, everyones

2. the implementation was poor

needs are as dierent as the collection

3. the app tried to do too much

of apps on their various devices.


Focusing on a specic function also

Keeping the app as simple as possible

makes for a less cluttered app one

(especially in version 1) is the best way to

that is easier for the customer to

avoid all three pitfalls. Most successful

understand and for the developer to

apps (indeed, most successful consumer

build. As a result, an MVP will probably

tech products) are based on what is

perform better technically and its value

called an MVP, or minimum viable

will be easier for both the developer and

product. Its the product with the

buyer to discern.

smallest feature set that can deliver the


core function without any distracting
bells and whistles. You know you have
an MVP if the product would no longer
function if you removed any single
feature.

The best example is the original Google


Search. Whereas todays Google Search
oers more than 20 special features
beyond the original word search
capability (e.g., synonyms, weather

So, in drawing up your MVP feature list,

forecasts, stock quotes, maps, transla-

ask yourself what features are key to the

tion) the original product was simply text

experience. Possible must-haves include:

search where the user types into a


search box at the top of an otherwise

Oine capability (i.e., ability to work

all-but-empty web page and gets back a

when not connected to the Internet)

page full of text search results.

HOW TO BUILD AN APP: ANDROID EDITION


Location aware (i.e., will the app use

MVP Takeaways

GPS?)
NFC (i.e., can devices share data by

MVP = Minimal Viable

touching?)

Product

Push notication (i.e., sending


updated information to devices as

Its the product with the

soon as it is available)

smallest feature set that


Draw up your feature lists knowing

can deliver the core func-

which features are necessary and which

tion

are there primarily to enhance the user


experience. Push notications, for

You have an MVP if the

example, are not key to Instagram but

product would no longer

the app has them anyway to encourage

function if you removed

user activity. Features that are there

any single feature

solely to enhance the user experience


may have to wait for version 2. (The rst

An MVP will probably

iPod only came in only one color and

perform better technically

could just hold 1000 songs.)

and its value will be easier


for both the developer and
buyer to discern

Once you have your feature list, the next


step is design to decide where and
how to implement the features on the
device, in the cloud, or in some combination. Most app design decisions fall into
two broad categories: user experience
and shared information. Which takes us
to the next step.

Step 3
DESIGN YOUR APP

HOW TO BUILD AN APP: ANDROID EDITION


User experience (UX) decisions

(the HTML5 part) sits within an applica-

determine the apps look and feel. They

tion wrapper (the Java part) that

answer questions such as: What does

implements less dynamic content such

the app look like? What screens does it

as the apps widgets. Which part of the

have? In the app world, onscreen objects

app is HTML5 and which is Java is not

like buttons, sliders, and ll-in boxes are

obvious to the untrained eye (there may

called widgets. So you need to decide

be no browser address bar, for example)

which types of widgets will reside on

but implementing the app this way

which screens. What actions will occur as

enables much faster content refresh (via

a result of the user interacting with

the web) and more response widgets

those widgets?

(via Java). HTML5s write once, deploy


anywhere model is also another

Keep in mind that users will expect to

advantage. Parts of the app written in

interact dierently with a mobile device

HTML5 can be deployed across iPhones,

than they do with a PC because the

iPads and Android devices without

screens on mobile devices are much

rewrite.

smaller. Theyll expect to use their


ngers instead of a mouse or a trackpad.

In addition to deciding what happens on

Ideally, your app can even be used with

the frontend, you also have to decide

one hand holding the device while using

what happens on the backend

just a thumb for scrolling and working

specically, what data will users share?

the apps other controls the Path app

For example, will users want to broad-

is a good example, and increasingly so is

cast their GPS locations to other users

Facebook.

in real time (such as to enhance a


gaming experience)? Will the app share

You will also need to decide which parts

or store movie or restaurant preferences

(if any) of your application to write in

or purchase histories with backend

HTML5 and which to write in Java, the

recommendation engines? If so, these

primary programming language for

functions will most likely call the APIs

Android devices. For reasons of speed

of backend service providers you

and programming eciency, many apps

wont actually have to write those

(like Facebook) are designed a little like

functions yourself.

1960s-era TV sets where a small window


of frequently updated content

HOW TO BUILD AN APP: ANDROID EDITION

ID
O
R
D
N
A
Y
H
W

CrossCompatibility

Open
Platform

Market
Growth

International
Growth

Free
Tools

For the time being, then, set those

Android platform. Some of the reasons

backend functions aside and focus on

to develop for Android include:

the front end. Just like you want to build


a product with the minimal viable

1. Cross-Compatibility

number of features, you may also wish

There are well over 100 million Android

to build your rst prototype using

devices in use today, representing

dummy data thats static rather than

hundreds of dierent models from

shared. Its much easier to ne-tune the

dozens of dierent manufacturers.

frontend if you dont have to simultane-

Companies as varied as Samsung,

ously modify your backend too. Once

Motorola, LG, HTC, etc. make devices

you get the apps look-and-feel right,

that will run Android apps and these

then make those backend connections.

devices come in many dierent screen


sizes and resolutions. Android-capable

Why Android?

devices also come in dierent congura-

Besides the features and design of your

tions of hardware features, such as

rst app, theres one other decision you

camera, accelerometer, GPS, and

need to make before you start actual

Bluetooth yet they all run Android

development. Thats whether to deploy

and all are available to you as potential

on Apples iOS platform or on Googles

targets for your Android app.

10

HOW TO BUILD AN APP: ANDROID EDITION


2. Open Platform
Androids cross-compatibility stems from

4. International Growth

the fact that it is an open platform,

In particular, Android overwhelmingly

meaning that any company can

dominates markets outside the U.S.

download the free source code and

According to China Daily, Android

build products based on that code. You

accounted for 66% of the Chinese

can view and modify the code as you

smartphone market in the rst half of

wish to create new features, or to

2013.

handle an existing feature in a new way.


5. Free Tools
3. Market Growth

All the tools you need to develop rich

As noted earlier, the Android market is

Android apps are free of charge. Step 4

huge and growing fast thanks to its

is about installing those tools and setting

openness and compatibility across so

up your Android development environ-

many devices and device makers.

ment.

Androids openness and market growth


also make for a highly innovative

Why Not Android?

environment where the next big thing

Although Android oers many compel-

is likely to happen. Thats a very

ling advantages as a platform for your

attractive proposition for developers.

mobile app, it also has some disadvantages. Here are three:

DROID
N
A
t
o
N
Y
H
W

Customers less
willing to pay

High diversity
of devices

11

Not in the
Apple ecosystem

HOW TO BUILD AN APP: ANDROID EDITION

1. Customers less willing to pay


Perhaps it's because of Android's open
source heritage, but whatever the
reason, Android users pay less for apps.
The average selling price for an Android
app was just 6 cents in April 2013 versus
19 cents for iPhone apps and 50 cents
for iPad app -- according to data
furnished by Flurry Analytics, Google
Play and the Apple App Store.
3. Not in the Apple Ecosystem
2. High diversity of devices

Some developers and users prefer

Building an app that runs successfully on

Apples closed and more tightly

so many dierent screen sizes and

controlled environment to Android.

resolutions continues to be a challenge

Apples ecosystem, consisting of iCloud,

despite the fact that Android has

iTunes, the App Store, the iPad, the

provided innovations such as Fragments

iPhone, Mac computers, etc., oers a

and GridLayout. Android introduced

very holistic user experience with the

Fragments in Android 3.0 (API level 11),

ability to share data seamlessly across

primarily to support more dynamic and

devices plus the assurance of having

exible user interface designs on large

applications pre-approved for quality

screens, such as tablets. A Fragment is a

and content prior to going on sale.

Java class that enables tablets to display


side-by-side on one screen content that
on a phone could not be displayed all at
once on the same screen and so
would be displayed on multiple screens.
GridLayout is a class that places its
children in a rectangular grid composed
of a set of innitely thin lines that
separate the viewing area into cells.

12

Step 4

SET UP YOUR ANDROID


DEVELOPMENT ENVIRONMENT

Java Dev Kit

Android SDK

Eclipse IDE

Android ADT

13

HOW TO BUILD AN APP: ANDROID EDITION


Android apps are typically written as Java

3. Eclipse IDE (integrated develop-

classes. That source code is then

ment environment)

compiled into bytecode that the Dalvik

Included in the Android SDK download,

engine (a subset of a Java Virtual

the Eclipse IDE provides the hands-on

Machine) runs under the Android

controls you need for writing your app

operating system. The following steps

using Java, the Android SDK and the

describe how to acquire and congure

Android ADT.

the tools you need to write your apps


Java classes and then test and package

4. Android ADT (Android Development

the app for deployment. NOTE: By the

Tools) This Eclipse plug-in performs

time you read this, these instructions

much of the housekeeping involved in

may have changed. Please refer to the

creating an Android app such as creating

Android Developers Website for current

the needed les and overall structure.

updates.
Installing the JDK
For Android app development youll

To install the ocial Oracle Java SE SDK

need four basic toolsets:

(JDK) for Windows, OS X, and Linux go to


the Oracle Java website and follow the

1. The Java Development Kit (JDK)

instructions.

This is the Software Development Kit


(SDK) for Java and provides the founda-

Installing the Android SDK

tion for the Android SDK.

At this point you still need to acquire the


Java les needed to compile an Android

2. Android SDK

app as well as some additional build

This consists of all the tools you need to

tools and the les required to run an

develop and test your app:

Android emulator. To access these

Eclipse + ADT plugin

add-ons, look inside the tools/ directory

Android SDK Tools

of the Android SDK you just downloaded

Android Platform-tools

and run the Android batch le or shell

The latest Android platform

script. That opens the Android SDK

The latest Android system image for

Manager. Make sure the following items

the emulator

are checked and then click Install.

14

HOW TO BUILD AN APP: ANDROID EDITION


SDK Platform for all Android SDK

Android versions and samples along

releases you want to test against

with all system images. Obviously, this

ARM EABI v7a System Image

approach takes up the most amount of

Documentation for Android SDK

space on the system.

Samples for SDK


Google APIs by Google Inc. for the

Once all the selected items are installed

Android SDK release youre download-

(it may take several hours if you have a

ing

slow Internet connection), you are ready

Android SDK Tools and Platform-

to begin making your Android app!

tools
Android Support Library (in the

Development Takeaways

Extras group at the bottom of the

tree)

Android apps are written as

Java classes
Another Extra you can check to install is

the Intel Hardware Accelerated Execu-

Source code is compiled into

bytecode that the Dalvik

tion Manager (HAXM), a hardwareassisted virtualization engine that makes

engine runs under the Android

your app run faster when you run it in

operating system

an emulator (i..e., you are not running it


on an actual physical smartphone or

Four Basic Toolsets

tablet). The HAXM requires a supported


Intel processor and Microsoft Windows

1. Java Development Kit

operating system version. Check the

2. Android SDK

HAXM installation instructions on the

3. Eclipse IDE

Intel website for further details.

4. Android ADT

One shortcut that many developers like


to use is to install everything with a
single command. Just type the following
command at the command line:
android update sdk --no-u

This will perform a full install of all

15

Step 5
DEVELOPING YOUR APP

16

HOW TO BUILD AN APP: ANDROID EDITION

With the development environment

In the New Android Application panel

installed, the next step is to launch

enter the following information:

Eclipse and begin making your app. For

For Application Name and Project

this step, we will walk through two

Name enter My First App

examples: My First App and Test

For Package Name enter

Drive. The rst app displays a button on

com.example.myrstapp

the phone push the button to display

For Build SDK select Android 4.2

the text, Hello World. The second app

For Minimum Required SDK,

uses the Kinvey backend service. In that

choose API 9: Android 2.3

app there are four buttons Save,

(Gingerbread)

Load One, Load All, Load Query, and

Uncheck Create custom launcher

Delete One.

icon
Click Next

To get started on My First App, Launch


Eclipse and select File > New > Project to

This brings up the Create Activity page.

bring up the New Project wizard.

Click BlankActivity and then Next

Choose Android Application Projectand


click Next.

This brings up the New Blank Activity


page.
For Activity Name enter
MainActivity

17

HOW TO BUILD AN APP: ANDROID EDITION

For Layout Name enter

AndroidManifest.xml

activity_main

This XML le is called the manifest. It is a

For Title enter MainActivity

conguration le that tells Android what

Keep the remaining defaults as is

your app contains. The manifest for My

Click Finish The Eclipse Package

First App looks like the image below.

Explorer now appears. It shows the

The two key parts of the manifest are its

various folders containing the les that

root, the <manifest> element, and that

Eclipse will use to build your Android

elements primary child, the

app. When you make an app you do so

<application> element. Among other

by working on the les within this

things, the <manifest> element supplies

hierarchy. Eclipse is context sensitive so

the name of your apps package,

clicking on a le brings up an appropri-

uniquely identifying your app to the

ate wizard, graphic tool or text editor for

device running it and to the Google Play

working on that le.

Store. The <application> element

Eclipse just created one of these les for

supplies the name for the class imple-

you.

menting activity (MainActivity) and an


<intent-lter> describing under what
conditions Android displays the activity.

18

HOW TO BUILD AN APP: ANDROID EDITION


The default intent lter, as in this case, is

The drawable les, meanwhile, contain

for the activity to appear in the launcher

static images sized appropriately for

so users can choose to run it. Note that

particular ranges of screen sizes, such as

an app can have any number of activities

drawable-mdi, which contains images

an activity is the apps behavior

sized for medium size screens.

associated with a particular screen.


libs/
You can easily add or change various

This folder contains third-party Java JARs,

parts of the manifest, such to enable

such as those required to communicate

various permissions or screen sizes, by

with the Kinvey backend. You can use

using the Eclipse manifest structured

the Eclipse Navigate and Search

editor. To show it, just double click

functions to nd and import these JARs

AndroidManifest.xml in the Package

to your libs/ directory.

Explorer.
scr/
Besides the manifest, other elements in

Holds the applications Java source code

the application package to note are:

(which you can edit directly).

res/

gen/

Modifying this item is where much of

Where Eclipse build tools place the Java

your actual app making work is done. It

source code (in R.java) they generate (for

holds resources such as drawable icons

example, after you import a JAR or

and GUI layouts that are packaged with

modify a layout, close and then reopen

the compiled Java in the application. For

the project).

example, the layout folder contains XML


les that determine the positioning and

bin/

size of text boxes, buttons and other

Holds the compiled application.

layout elements for a particular activity


and also attach onClick methods to
them. Double clicking on a layout (in our
case, thats activity_main.xml) brings up
the Eclipse graphical layout editor. As
you drag and drop items into place the
editor generates the appropriate XML.

19

HOW TO BUILD AN APP: ANDROID EDITION


To complete My First App, we need to

attach to the button (an on click

add the button to the layout and also the

listener that responds when the

text to be displayed when the user taps

button is clicked). Lets type the

the button. To do that, click on

method name: showHelloWorld.

activity_main.xml within layout in the

On the text box, type the string:

Package Explorer. Eclipse opens the

@string/hello_world. This references a

layout editor, which has both a graphical

constant (Hello World!) in strings.xml

mode and an XML text-editing mode. In

in the values folder.

the graphical mode, follow these steps:


Using a relative reference rather than a
Draw a button and a text box in the

constant means if we ever wish to

layout.

change the displayed text, we need only

On the button, type the word

make the change in one place rather

Button.

than everywhere that string might be

Select the button youve just drawn

used.

and click the On Click item in the


Properties palette.

Switching to text-editing shows us the

In the blank space just to the right of

resulting XML (except for the missing

On Click in the Properties Pallet type

text, in red):

the name of a method you wish to

--

20

HOW TO BUILD AN APP: ANDROID EDITION


Type in the missing code manually. Now

Eclipse automatically detects the phone

the Hello World! text will be hidden

and asks whether you wish to run the

until the button is pressed.

app on the phone or in the emulator.

Finally, we will supply the logic for the

Congratulations! Your app is done. Now

onClick method we have just named. To

might be a good time to toast your

do that open the src item in the Package

accomplishment.

Explorer and click the MainActivity.java


le. Then type in the methods Java code,
here shown in red:

Note that the methods signature must

Making a Toast

be public and must include only one

One of the convenient features that

parameter, which is the view parameter.

Android oers developers is the ability


to build alerts, or toast messages, into

To run the app, click Run in the Eclipse

applications without writing much code.

toolbar. The app will run in the built-in

Typically these alerts are displayed in a

Android emulator, as shown in the

reserved area at the top or bottom of

gure. If you plug your phone into your

the phones screen whenever a predeter-

computer via a USB cable, you can also

mined event occurs.

run the app on your own phone.


21

HOW TO BUILD AN APP: ANDROID EDITION


For example, suppose we wanted the

Backend as a Service (BaaS) providers, as

app we just built, My First App, to display

theyre called, compete on a variety of

the toast Button onClick Triggered!

features and benets, one of which is

when the button is clicked. To do that we

how easy it is to connect to your app. So,

simply add the following code, shown

chances are, it will be a pretty easy

here in red, to our Java source:

process including 8 steps.

1. Download the providers SDK to


your computer; this contains the
software that lets your app talk to the
backend
2. Create an account on the providers
website, usually with a credit card
3. Follow the providers instructions to
The makeText method invokes the string

install the downloaded les into your

referenced by TOAST_TEXT, which the

application package (e.g., place the

show method displays.

JARs in the libs folder)


4. Add your app on the backend and

Connecting To a Backend as a Service

type in your apps name where

One factor mentioned earlier thats

requested

fueling apps explosive growth is the

5. Congure your backend data model

availability of Cloud-based backend

(i.e., a collection of objects)

services. These are useful when your

6. Locate your apps backend service

app needs more data than can be

credentials used to authenticate the

reasonably stored on a mobile device

app with the backend copy them

and/or the data must be accessible by

into your apps source code

multiple devices. Connecting your app to

7. Create a static app handle used to

a commercial backend means you dont

identify the app on backend calls

have to provide that service yourself

8. Map your apps data to your

eectively leveling the playing eld for

backend model

anyone who cant aord to build their


own app backend versus larger organiza-

Heres how this would work with Kinvey

tions that can.

and our second example app, Test Drive.

22

HOW TO BUILD AN APP: ANDROID EDITION


The app, as previously noted, displays
Save, Load One, Load All, Load
Query, and Delete One buttons.
Tapping the Save button saves some
static dummy data to the backend and
displays a Save worked! message (or
Save failed! if the save did not work).
Tapping the Load One button loads the
saved data from the backend to the

Figure X

device and displays a Load worked!


message (or Load failed! if the load did
not work).

Figure Y

These labels tag the dummy TestObject


data the app passes to TestObjects on
the backend when the user taps the
Save button. Similarly, when the user
Figure X shows the My Apps page on

taps the Load button the app retrieves

Kinvey with Test Drive already added

a TestObject from the backend TestOb-

and its application credentials displayed

jects.

(by clicking the Credentials link). Figure


Y shows the backend collection (named

For these operations to happen the

TestObjects) for the Test Drive app. Note

Kinvey SDK must have been downloaded

the _id and name columns with the

(see Kinveys Download Page) and these

labels 12345 and My rst data!

SDK contents installed into the project.

respectively. (When conguring a

After downloading the zip le, extract

collection, use the + and - buttons to

the contents and open the `libs`

add and delete columns.)

directory. Copy the contents of this


directory into the `libs` directory of your
Android project.
23

HOW TO BUILD AN APP: ANDROID EDITION

The complete Test Drive project can be downloaded from here. To illustrate
steps 6 and 8 listed above, however, we will highlight some specic sections of
the code. Lets start with step 6, authentication.

To authenticate the app to Kinvey, the auto-generated credentials must be


copied into the app, replacing your_app_key and your_app_secret in these
lines:

In step 7 we provide a private handle for calls to Kinvey:

Step 8 is mapping the app data to the model we just congured at Kinvey. You
can use any class that extends the GenericJson class, in this app example,
thats a TestEntity class that has a string name. It looks like this:

24

HOW TO BUILD AN APP: ANDROID EDITION

Now lets look at the method that does the save. The method is called in the
onClickListener of the save_button. When the activity loads, it will create a new
static TestObject with id "12345". When the save button is clicked the following
method will trigger the dummy TestObject to be saved in the testObjects collection.

Here line 2 creates a handle to the backend collection where the object is saved.
Lines 3 through 21 save the object and displays an alert if the save is either
successful or fails. Likewise, the load method looks like this:

Line 2 creates a handle to the backend collection that has the object to load. Line 3
instantiates an instance of TestObject for the library into which the data is loaded
from the backend. And lines 4 through 23 load the object and display an alert if the
load is either successful or fails.
25

HOW TO BUILD AN APP: ANDROID EDITION


Welcome To Our World!
The key takeaway from all this is that
making an app is a worthwhile thing to
do for anyone with a clever idea and a
working knowledge of Java. The proof is
in the hundreds of apps succeeding in
the market every day, many written by
people working on their own and who
never wrote an app before in their lives.
As with anything else, practice does
make perfect. But hopefully with all the
resources available, and the knowledge
gained from this ebook, you have
already started down the path toward
joining the growing legions of Android
app developers. If so, we welcome you!

26

Written by
Morgan Bickle

Randall Cronk

On any given day you'll nd Morgan

Since 1990, Randall has helped over 250

programming mobile SDKs, building

high-tech companies convey the value

backend APIs, and discussing the future

of what they do through white papers,

of web and mobile technology. As part of

web content, brochures, case studies

the core founding team at Kinvey and

and articles. Based today in downtown

now the CTO, he owns Kinveys

Boston, he was previously a vice

technology vision. Prior to Kinvey, he

president with Regis McKenna where he

wrote enterprise software for a decade.

ran the Digital Equipment account.

Designed by
Jake McKibben and Lauren Pedigo

What is Kinvey? Kinvey makes a fully-featured Backend as a


Service solution, oering 3rd party data integrations, multiplatform support, push notications, and custom business logic on
a platform where it's free to get started and you only pay when
your app is successful.

Build your backend today

Das könnte Ihnen auch gefallen