2. Table of Contents
How to Build an App: Android Edition
1 What’s All the Excitement About?
3 Step 1: Decide What New Thing You Want to Do
5 Step 2: Define Your MVP
8 Step 3: Design Your App
13 Step 4: Set up Your Android Development Environment
16 Step 5: Developing Your App
i
3. HOW TO MAKE AN APP: ANDROID EDITION
What’s All the Excitement About? NFC is useful for actions like automated
It’s 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 offering special deals to customers in a
you tap into Android’s market leading specific 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 offers 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 offers
accelerometers that know when the market-leading capabilities for letting
phone is moving, in which direction and applications on the same device invoke
how fast; and many include NFC (Near each other’s services. That way a
Field Communications), a technology developer is spared the work of imple-
that enables easy communications (such menting and replicating an already-exist-
as by tapping) between two devices or ing service.
between a device and a passive tag.
Besides its technical advantages, Android
also offers developers major business
opportunities.
1
4. HOW TO MAKE AN APP: ANDROID EDITION
According to Google, there were over “The Cloud” is a general term meaning a
700,000 apps available on Google Play in service that users and applications share
October 2012 and there were over 25 via the Internet. A cloud may be “private”
billion downloads in September 2012. — i.e., the services belong to an
According to IDC, as of Q3 2012 Android organization for the benefit of its
accounted for 75% of all smartphone employees and business partners. Or a
shipments — in a market that did not cloud may be “public” — i.e., a company
exist until 2008. (such as Amazon or Kinvey) owns the
services, which it offers commercially to
“ Two recent developments in
particular have sparked
the public, including app developers. In
the Android space, Cloud services
typically function as an app’s “backend.”
(Android) growth: the An-droid They may do computational tasks
ecosystem and the cloud
considered too “heavy” for a phone.
” They might also store, secure and share
data among multiple users on different
phones. A good example is a game app
Two recent developments in particular where users need to access the current
have sparked this growth: the Android state of play.
ecosystem and the Cloud. The ecosys-
tem 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 it’s a
in distributing and selling traditional PC service that’s fairly typical across lots of
applications. There’s 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 off
paid. You simply register online, pay a hooking into a commercial backend
nominal fee, upload the app and you’re provider via an API.
in business.
2
6. HOW TO MAKE AN APP: ANDROID EDITION
Then you can focus on what counts most information, with another NFC phone
— a unique user experience and just by tapping the two phones together.
application-specific functionality. That
brings us to the first step in making an Other app opportunities involve
app. information sharing. A prime example of
that is Google Docs that lets different
Why do people buy apps? Why do they users on different 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 accelerome- movie, and later picks up the action at
ters 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 people’s lives. That
information at just the right time.
requires, first, identifying the value to be
It tells you today’s weather before you
provided, second, conceptualizing a core
start your day, how much traffic 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 you’re
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 they’re
playing. And the best part? All of this research part is easy since you can
happens automatically. Cards appear probably find 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 let’s 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
4
8. HOW TO MAKE 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 specific need, everyone’s
2. the implementation was poor needs are as different as the collection
3. the app tried to do too much of apps on their various devices.
Focusing on a specific 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. It’s 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 today’s Google Search
offers 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 • Offline 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.
6
9. HOW TO MAKE AN APP: ANDROID EDITION
• Location aware (i.e., will the app use
GPS?)
MVP Takeaways
• NFC (i.e., can devices share data by
• MVP = Minimal Viable
touching?)
• Push notification (i.e., sending Product
updated information to devices as
soon as it is available) • It’s the product with the
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 notifications, 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 first • 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
Once you have your feature list, the next buyer to discern
step is design — to decide where and
how to implement the features on the
device, in the cloud, or in some combina-
tion. Most app design decisions fall into
two broad categories: user experience
and shared information. Which takes us
to the next step.
7
11. HOW TO MAKE AN APP: ANDROID EDITION
User experience (UX) decisions (the HTML5 part) sits within an applica-
determine the app’s 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 app’s 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 fill-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). HTML5’s “write once, deploy
anywhere” model is also another
Keep in mind that users will expect to advantage. Parts of the app written in
interact differently 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. They’ll expect to use their
fingers 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 specifically, what data will users share?
the app’s 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 efficiency, many apps won’t 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
9
12. HOW TO MAKE AN APP: ANDROID EDITION
•
?
W HY ANDROID
Cross- Open Market International Free
Compatibility Platform Growth Growth 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 first prototype using devices in use today, representing
“dummy” data that’s static rather than hundreds of different models from
shared. It’s much easier to fine-tune the dozens of different manufacturers.
frontend if you don’t have to simultane- Companies as varied as Samsung,
ously modify your backend too. Once Motorola, LG, HTC, etc. make devices
you get the app’s look-and-feel right, that will run Android apps — and these
then make those backend connections. devices come in many different screen
sizes and resolutions. Android-capable
Why Android? devices also come in different configura-
Besides the features and design of your tions of hardware features, such as
first app, there’s one other decision you camera, accelerometer, GPS, and
need to make before you start actual Bluetooth — yet they all run Android —
development. That’s whether to deploy and all are available to you as potential
on Apple’s iOS platform or on Google’s targets for your Android app.
10
13. HOW TO MAKE AN APP: ANDROID EDITION
2. Open Platform 4. International Growth
Android’s cross-compatibility stems from In particular, Android overwhelmingly
the fact that it is an open platform, dominates markets outside the U.S. For
meaning that any company can example, it accounts for over 90%
download the free source code and market share in
build products based on that code. You China (Q3, 2012) according to
can view and modify the code as you Beijing-based Analysis International as
wish to create new features, or to reported by Tech In Asia.
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.
Android’s openness and market growth
also make for a highly innovative Why Not Android?
environment where “the next big thing” Although Android offers many compel-
is likely to happen. That’s a very ling advantages as a platform for your
attractive proposition for developers. mobile app, it also has some disadvan-
tages. Here are three:
ROID ?
W HY Not AND
Customers less High diversity Not in the
willing to pay of devices Apple ecosystem
11
14. HOW TO MAKE 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 apps generate less than
10% of the total dollars spent on mobile
apps, despite having 75% of the
smartphone market itself — and despite
the fact that the average selling price of
an app in the Android Market is $3.79
versus Apple App Store’s $2.01. In other
words, Android users are reluctant to
spend money on apps.
3. Not in the Apple Ecosystem
2. High diversity of devices Some developers and users prefer
Building an app that runs successfully on Apple’s closed and more tightly
so many different screen sizes and controlled environment to Android.
resolutions continues to be a challenge Apple’s 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., offers 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
flexible 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 infinitely thin lines that
separate the viewing area into cells.
12
15. Step 4
SET UP YOUR ANDROID
DEVELOPMENT ENVIRONMENT
Java Dev Kit
Android SDK
Eclipse IDE
Android ADT
13
16. HOW TO MAKE 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 configure Android ADT.
the tools you need to write your app’s
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 files and overall structure.
updates.
Installing the JDK
For Android app development you’ll To install the official 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 files 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 files 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 file 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
17. HOW TO MAKE AN APP: ANDROID EDITION
• “SDK Platform” for all Android SDK
releases you want to test against Development Takeaways
• “ARM EABI v7a System Image”
• Android apps are written as
• “Documentation for Android SDK”
• “Samples for SDK”
Java classes
• “Google APIs by Google Inc.” for the • Source code is compiled
Android SDK release you’re download- into bytecode that the Dalvik
ing
engine runs under the
• Android SDK Tools and
Platform-tools
Android operating system
• Android Support package (in the
Extras group at the bottom of the Four Basic Toolsets
tree)
1. Java Development Kit
One shortcut that many developers like
2. Android SDK
to use is to install everything with a 3. Eclipse IDE
single command. Just type the following 4. Android ADT
command at the command line:
android update sdk --no-u
This will perform a full install of all
Android versions and samples along
with all system images. Obviously, this
approach takes up the most amount of
space on the system.
Once all the selected items are installed
(it may take several hours if you have a
slow Internet connection), you are ready
to begin making your Android app!
15
19. HOW TO MAKE 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 com.ex-
Drive.” The first app displays a button on ample.myfirstapp
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 (Ginger-
app there are two buttons — push one bread)”
button and it saves static data to the • Uncheck “Create custom launcher
backend and the app displays text that icon”
the save was successful. Push the other • Click “Next”
button and the app loads the data to the
phone from the backend and displays This brings up the “Create Activity” page.
text saying the load was a success. • Click “BlankActivity” and then “Next”
To get started on My First App, Launch This brings up the “New Blank Activity”
Eclipse and select File > New > Project to page.
bring up the “New Project” wizard. • For “Activity Name” enter
Choose “Android Application Project”and MainActivity
click “Next.”
17
20. HOW TO MAKE AN APP: ANDROID EDITION
• For “Layout Name” enter activity_- AndroidManifest.xml
main This XML file is called the manifest. It is a
• For “Title” enter MainActivity configuration file 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 files that root, the <manifest> element, and that
Eclipse will use to build your Android element’s primary child, the <applica-
app. When you “make an app” you do so tion> element. Among other things, the
by working on the files within this <manifest> element supplies the name
hierarchy. Eclipse is context sensitive so of your app’s package, uniquely
clicking on a file brings up an appropri- identifying your app to the device
ate wizard, graphic tool or text editor for running it and to the Google Play Store.
working on that file. The <application> element supplies the
Eclipse just created one of these files for name for the class implementing activity
you. (MainActivity) and an <intent-filter>
describing under what conditions
Android displays the activity.
18
21. HOW TO MAKE AN APP: ANDROID EDITION
The default intent filter, as in this case, is The “drawable” files, 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 app’s 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 find and import these JARs
AndroidManifest.xml in the Package to your libs/ directory.
Explorer.
scr/
Besides the manifest, other elements in Holds the application’s 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
files 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, that’s 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
22. HOW TO MAKE 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). Let’s type the
the button. To do that, click on activity_- method name: showHelloWorld.
main.xml within layout in the Package • On the text box, type the string:
Explorer. Eclipse opens the layout editor, @string/hello_world. This references a
which has both a graphical mode and an constant (Hello World!) in strings.xml
XML text-editing mode. In the graphical in the values folder.
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 you’ve 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
23. HOW TO MAKE 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
file. Then type in the method’s Java code,
here shown in red:
Note that the method’s 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 offers 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
figure. If you plug your phone into your the phone’s screen whenever a predeter-
computer via a USB cable, you can also mined event occurs.
run the app on your own phone.
21
24. HOW TO MAKE 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 they’re called, compete on a variety of
the toast “Button onClick Triggered!” features and benefits, 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 provider’s SDK to
your computer; this contains the
software that lets your app talk to the
backend
2. Create an account on the provider’s
website, usually with a credit card
3. Follow the provider’s instructions to
The makeText method invokes the string install the downloaded files 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 app’s name where
One factor mentioned earlier that’s requested
fueling apps’ explosive growth is the 5. Configure your backend data model
availability of Cloud-based backend (i.e., a collection of objects)
services. These are useful when your 6. Locate your app’s 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 app’s source code
multiple devices. Connecting your app to 7. Create a static app handle used to
a commercial backend means you don’t identify the app on backend calls
have to provide that service yourself — 8. Map your app’s data to your
effectively leveling the playing field for backend model
anyone who can’t afford to build their
own app backend versus larger organiza- Here’s how this would work with Kinvey
tions that can. and our second example app, Test Drive.
22
25. HOW TO MAKE AN APP: ANDROID EDITION
The app, as previously noted, displays
“Save” and “Load” 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”
button loads the saved data from the Figure X
backend to the 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
taps the “Load” button the app retrieves
a TestObject from the backend TestOb-
Figure X shows the “My Apps” page on jects.
Kinvey with Test Drive already added
and its application credentials displayed For those operations to happen the
(by clicking the “Credentials” link). Figure Kinvey SDK must have been downloaded
Y shows the backend collection (named (see Kinvey’s “Getting Started” page) and
TestObjects) for the Test Drive app. Note these SDK contents installed into the
the “_id” and “name” columns with the project:
labels “12345” and “My first data!”
respectively. (When configuring a • kinvey-1.4.1.jar and kinvey-1.4.1.-
collection, use the “+” and “-“ buttons to jar.properties to the libs folder
add and delete columns.) • urbanairship-lib-1.1.5.jar from the
ua-android-lib-1.1.5 directory to the
libs folder
• kinvey-1.4.1-javadoc folder to a docs
folder in the base project directory
23
26. HOW TO MAKE 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 specific sections of
the code. Let’s 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 configured at Kinvey. You
can use any class that implements the MappedEntity interface, in this app
example, that’s a TestEntity class that has a string name. It looks like this:
24
27. HOW TO MAKE AN APP: ANDROID EDITION
Now let’s 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
28. HOW TO MAKE 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
29. Written by
Morgan Bickle Randall Cronk
On any given day you'll find 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 Kinvey’s 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, offering 3rd party data integrations, multi-plat-
form support, push notifications, 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