How to Make an App: Android Edition

1,635 views
1,581 views

Published on

Kinvey’s eBook titled, “How to Make an App: Android Edition” is a step by step guide written by developers, for developers.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,635
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
40
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

How to Make an App: Android Edition

  1. 1. How to Make an App:ANDROID EDITION
  2. 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. 3. HOW TO MAKE AN APP: ANDROID EDITIONWhat’s All the Excitement About? NFC is useful for actions like automatedIt’s never been easier or quicker to build store checkout, inventory counting,and distribute an application to millions contact information exchange, andof devices and get paid, especially when offering special deals to customers in ayou tap into Android’s market leading specific store aisle.features.“We are living in the Post-PC era.” Thatsentence — in quotes — comes up over14,000 times in a Google search. So whatare so many people writing about? Theyare writing about a time when manycomputing tasks — such as staying intouch with friends, doing onlineresearch, shopping, and playing games Android also offers features not found on— no longer require a laptop or desktop other mobile platforms like iOS orcomputer. Not only can these activities Windows Phone that make developmentnow be done “on the go” with a smart- easier. Two good examples are thephone or tablet, but they can also be AccountManager system and thedone in new ways that enrich the AccountAuthenticatorActivity base class,experience. both of which streamline the process of setting up custom accounts — such as toAndroid devices are a great example. register and authenticate user IDs andMany are location-aware; many have passwords. Android also offersaccelerometers that know when the market-leading capabilities for lettingphone is moving, in which direction and applications on the same device invokehow fast; and many include NFC (Near each other’s services. That way aField 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. 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
  5. 5. Step 1DECIDE WHAT NEW THINGYOU WANT TO DO 3
  6. 6. HOW TO MAKE AN APP: ANDROID EDITIONThen 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. Thatbrings us to the first step in making an Other app opportunities involveapp. information sharing. A prime example of that is Google Docs that lets differentWhy do people buy apps? Why do they users on different devices work on themake them? The answer to both same document (in the Cloud) coopera-questions is that a successful app tively. A similar opportunity is contextimproves users’ lives in new ways — sharing such as when the user starts atypically by taking advantage of features movie on a smartphone, stops thelike location awareness and accelerome- movie, and later picks up the action atters 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 teams 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 theseawareness so apps can tailor the user tests? Good, then let’s proceed to theexperience based on location — such as next step.by recommending stores or restaurantsin that area. As previously noted, NFC isa feature that lets users easily exchangedata, such as photos or contact 4
  7. 7. Step 2DEFINE YOUR MVP 5
  8. 8. HOW TO MAKE AN APP: ANDROID EDITIONMost unsuccessful apps fail for any of It was enough to prove the conveniencethree 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 alsoKeeping 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 toavoid all three pitfalls. Most successful understand and for the developer toapps (indeed, most successful consumer build. As a result, an MVP will probablytech products) are based on what is perform better technically and its valuecalled an MVP, or minimum viable will be easier for both the developer andproduct. It’s the product with the buyer to discern.smallest feature set that can deliver thecore function without any distracting“bells and whistles.” You know you havean MVP if the product would no longerfunction if you removed any singlefeature.The best example is the original GoogleSearch. Whereas today’s Google Searchoffers more than 20 special featuresbeyond the original word searchcapability (e.g., synonyms, weather So, in drawing up your MVP feature list,forecasts, stock quotes, maps, transla- ask yourself what features are key to thetion) the original product was simply text experience. Possible must-haves include:search — where the user types into asearch box at the top of an otherwise • Offline capability (i.e., ability to workall-but-empty web page and gets back a when not connected to the Internet)page full of text search results. 6
  9. 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 thatDraw up your feature lists knowing can deliver the core func-which features are necessary and which tionare there primarily to enhance the userexperience. Push notifications, for • You have an MVP if theexample, are not key to Instagram but product would no longerthe app has them anyway to encourage function if you removeduser activity. Features that are there any single featuresolely to enhance the user experiencemay have to wait for version 2. (The first • An MVP will probablyiPod only came in only one color and perform better technicallycould just hold 1000 songs.) and its value will be easier for both the developer andOnce you have your feature list, the next buyer to discernstep is design — to decide where andhow to implement the features on thedevice, in the cloud, or in some combina-tion. Most app design decisions fall intotwo broad categories: user experienceand shared information. Which takes usto the next step. 7
  10. 10. Step 3DESIGN YOUR APP 8
  11. 11. HOW TO MAKE AN APP: ANDROID EDITIONUser experience (UX) decisions (the HTML5 part) sits within an applica-determine the app’s look and feel. They tion wrapper (the Java part) thatanswer questions such as: What does implements less dynamic content suchthe app look like? What screens does it as the app’s widgets. Which part of thehave? In the app world, onscreen objects app is HTML5 and which is Java is notlike buttons, sliders, and fill-in boxes are obvious to the untrained eye (there maycalled 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 waywhich screens. What actions will occur as enables much faster content refresh (viaa result of the user interacting with the web) and more response widgetsthose widgets? (via Java). HTML5’s “write once, deploy anywhere” model is also anotherKeep in mind that users will expect to advantage. Parts of the app written ininteract differently with a mobile device HTML5 can be deployed across iPhones,than they do with a PC because the iPads and Android devices withoutscreens on mobile devices are much rewrite.smaller. They’ll expect to use theirfingers instead of a mouse or a trackpad. In addition to deciding what happens onIdeally, your app can even be used with the frontend, you also have to decideone 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 usersFacebook. in real time (such as to enhance a gaming experience)? Will the app shareYou 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 backendHTML5 and which to write in Java, the recommendation engines? If so, theseprimary programming language for functions will most likely “call” the APIsAndroid devices. For reasons of speed of backend service providers — youand 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 windowof frequently updated content 9
  12. 12. HOW TO MAKE AN APP: ANDROID EDITION • ? W HY ANDROID Cross- Open Market International Free Compatibility Platform Growth Growth ToolsFor the time being, then, set those Android platform. Some of the reasonsbackend functions aside and focus on to develop for Android include:the front end. Just like you want to builda product with the minimal viable 1. Cross-Compatibilitynumber of features, you may also wish There are well over 100 million Androidto build your first prototype using devices in use today, representing“dummy” data that’s static rather than hundreds of different models fromshared. 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 devicesyou get the app’s look-and-feel right, that will run Android apps — and thesethen make those backend connections. devices come in many different screen sizes and resolutions. Android-capableWhy Android? devices also come in different configura-Besides the features and design of your tions of hardware features, such asfirst app, there’s one other decision you camera, accelerometer, GPS, andneed 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 potentialon Apple’s iOS platform or on Google’s targets for your Android app. 10
  13. 13. HOW TO MAKE AN APP: ANDROID EDITION2. Open Platform 4. International GrowthAndroid’s cross-compatibility stems from In particular, Android overwhelminglythe fact that it is an open platform, dominates markets outside the U.S. Formeaning that any company can example, it accounts for over 90%download the free source code and market share inbuild products based on that code. You China (Q3, 2012) according tocan view and modify the code as you Beijing-based Analysis International aswish to create new features, or to reported by Tech In Asia.handle an existing feature in a new way. 5. Free Tools3. Market Growth All the tools you need to develop richAs noted earlier, the Android market is Android apps are free of charge. Step 4huge and growing fast — thanks to its is about installing those tools and settingopenness and compatibility across so up your Android development environ-many devices and device makers. ment.Android’s openness and market growthalso 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 yourattractive 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. 14. HOW TO MAKE AN APP: ANDROID EDITION1. Customers less willing to payPerhaps it’s because of Android’s opensource heritage, but whatever thereason, Android apps generate less than10% of the total dollars spent on mobileapps, despite having 75% of thesmartphone market itself — and despitethe fact that the average selling price ofan app in the Android Market is $3.79versus Apple App Store’s $2.01. In otherwords, Android users are reluctant tospend money on apps. 3. Not in the Apple Ecosystem2. High diversity of devices Some developers and users preferBuilding an app that runs successfully on Apple’s closed and more tightlyso 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, theprovided innovations such as fragments iPhone, Mac computers, etc., offers aand GridLayout. Android introduced very holistic user experience with thefragments in Android 3.0 (API level 11), ability to share data seamlessly acrossprimarily to support more dynamic and devices plus the assurance of havingflexible user interface designs on large applications pre-approved for qualityscreens, such as tablets. A fragment is a and content prior to going on sale.Java class that enables tablets to displayside-by-side on one screen content thaton a phone could not be displayed all atonce on the same screen — and sowould be displayed on multiple screens.GridLayout is a class that places itschildren in a rectangular grid composedof a set of infinitely thin lines thatseparate the viewing area into cells. 12
  15. 15. Step 4SET UP YOUR ANDROIDDEVELOPMENT ENVIRONMENT Java Dev Kit Android SDK Eclipse IDE Android ADT 13
  16. 16. HOW TO MAKE AN APP: ANDROID EDITIONAndroid 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 appoperating system. The following steps using Java, the Android SDK and thedescribe how to acquire and configure Android ADT.the tools you need to write your app’sJava classes and then test and package 4. Android ADT (Android Developmentthe app for deployment. NOTE: By the Tools) This Eclipse plug-in performstime you read this, these instructions much of the housekeeping involved inmay have changed. Please refer to the creating an Android app such as creatingAndroid Developers Website for current the needed files and overall structure.updates. Installing the JDKFor Android app development you’ll To install the official Oracle Java SE SDKneed four basic toolsets: (JDK) for Windows, OS X, and Linux go to the Oracle Java website and follow the1. The Java Development Kit (JDK) instructions.This is the Software Development Kit(SDK) for Java and provides the founda- Installing the Android SDKtion for the Android SDK. At this point you still need to acquire the Java files needed to compile an Android2. Android SDK app as well as some additional buildThis consists of all the tools you need to tools and the files required to run andevelop 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. 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 KitOne shortcut that many developers like 2. Android SDKto use is to install everything with a 3. Eclipse IDEsingle command. Just type the following 4. Android ADTcommand at the command line: android update sdk --no-uThis will perform a full install of allAndroid versions and samples alongwith all system images. Obviously, thisapproach takes up the most amount ofspace on the system.Once all the selected items are installed(it may take several hours if you have aslow Internet connection), you are readyto begin making your Android app! 15
  18. 18. Step 5DEVELOPING YOUR APP 16
  19. 19. HOW TO MAKE AN APP: ANDROID EDITIONWith the development environment In the “New Android Application” panelinstalled, the next step is to launch enter the following information:Eclipse and begin making your app. For • For “Application Name” and “Projectthis step, we will walk through two Name” enter My First Appexamples: “My First App” and “Test • For “Package Name” enter com.ex-Drive.” The first app displays a button on ample.myfirstappthe 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 launcherbackend and the app displays text that icon”the save was successful. Push the other • Click “Next”button and the app loads the data to thephone 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” enterChoose “Android Application Project”and MainActivityclick “Next.” 17
  20. 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 itsvarious folders containing the files that root, the <manifest> element, and thatEclipse 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, theby working on the files within this <manifest> element supplies the namehierarchy. Eclipse is context sensitive so of your app’s package, uniquelyclicking on a file brings up an appropri- identifying your app to the deviceate wizard, graphic tool or text editor for running it and to the Google Play Store.working on that file. The <application> element supplies theEclipse just created one of these files for name for the class implementing activityyou. (MainActivity) and an <intent-filter> describing under what conditions Android displays the activity. 18
  21. 21. HOW TO MAKE AN APP: ANDROID EDITIONThe default intent filter, as in this case, is The “drawable” files, meanwhile, containfor the activity to appear in the launcher static images sized appropriately forso users can choose to run it. Note that particular ranges of screen sizes, such asan 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 communicatevarious permissions or screen sizes, by with the Kinvey backend. You can useusing the Eclipse manifest structured the Eclipse “Navigate” and “Search”editor. To show it, just double click functions to find and import these JARsAndroidManifest.xml in the Package to your libs/ directory.Explorer. scr/Besides the manifest, other elements in Holds the application’s Java source codethe 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 Javayour actual “app making” work is done. It source code (in R.java) they generate (forholds resources such as “drawable” icons example, after you import a JAR orand GUI layouts that are packaged with modify a layout, close and then reopenthe compiled Java in the application. For the project).example, the layout folder contains XMLfiles 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 tothem. Double clicking on a layout (in ourcase, that’s activity_main.xml) brings upthe Eclipse graphical layout editor. Asyou drag and drop items into place theeditor generates the appropriate XML. 19
  22. 22. HOW TO MAKE AN APP: ANDROID EDITIONTo complete My First App, we need to attach to the button (an “on clickadd the button to the layout and also the listener” that responds when thetext to be displayed when the user taps button is clicked). Let’s type thethe 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 awhich has both a graphical mode and an constant (Hello World!) in strings.xmlXML 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. 23. HOW TO MAKE AN APP: ANDROID EDITIONType in the missing code manually. Now Eclipse automatically detects the phonethe “Hello World!” text will be hidden and asks whether you wish to run theuntil 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. NowonClick method we have just named. To might be a good time to toast yourdo that open the src item in the Package accomplishment.Explorer and click the MainActivity.javafile. Then type in the method’s Java code,here shown in red:Note that the method’s signature must Making a Toastbe public and must include only one One of the convenient features thatparameter, which is the view parameter. Android offers developers is the ability to build alerts, or “toast” messages, intoTo 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 aAndroid emulator, as shown in the reserved area at the top or bottom offigure. 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. 24. HOW TO MAKE AN APP: ANDROID EDITIONFor example, suppose we wanted the Backend as a Service (BaaS) providers, asapp we just built, My First App, to display they’re called, compete on a variety ofthe toast “Button onClick Triggered!” features and benefits, one of which iswhen 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 easyhere 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 toThe makeText method invokes the string install the downloaded files into yourreferenced by TOAST_TEXT, which the application package (e.g., place theshow method displays. JARs in the libs folder) 4. Add your app on the backend andConnecting To a Backend as a Service type in your app’s name whereOne factor mentioned earlier that’s requestedfueling apps’ explosive growth is the 5. Configure your backend data modelavailability of Cloud-based backend (i.e., a collection of objects)services. These are useful when your 6. Locate your app’s backend serviceapp needs more data than can be credentials used to authenticate thereasonably stored on a mobile device app with the backend — copy themand/or the data must be accessible by into your app’s source codemultiple devices. Connecting your app to 7. Create a static app handle used toa commercial backend means you don’t identify the app on backend callshave to provide that service yourself — 8. Map your app’s data to youreffectively leveling the playing field for backend modelanyone who can’t afford to build theirown app backend versus larger organiza- Here’s how this would work with Kinveytions that can. and our second example app, Test Drive. 22
  25. 25. HOW TO MAKE AN APP: ANDROID EDITIONThe app, as previously noted, displays“Save” and “Load” buttons. Tapping the“Save” button saves some static dummydata to the backend and displays a “Saveworked!” message (or “Save failed! if thesave did not work). Tapping the “Load”button loads the saved data from the Figure Xbackend 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 addedand its application credentials displayed For those operations to happen the(by clicking the “Credentials” link). Figure Kinvey SDK must have been downloadedY shows the backend collection (named (see Kinvey’s “Getting Started” page) andTestObjects) for the Test Drive app. Note these SDK contents installed into thethe “_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 folderadd 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. 26. HOW TO MAKE AN APP: ANDROID EDITIONThe complete Test Drive project can be downloaded from here. To illustratesteps 6 and 8 listed above, however, we will highlight some specific sections ofthe code. Let’s start with step 6, authentication.To authenticate the app to Kinvey, the auto-generated credentials must becopied into the app, replacing “your_app_key” and “your_app_secret” in theselines: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. Youcan use any class that implements the MappedEntity interface, in this appexample, that’s a TestEntity class that has a string name. It looks like this: 24
  27. 27. HOW TO MAKE AN APP: ANDROID EDITIONNow let’s look at the method that does the save. The method is called in theonClickListener of the save_button. When the activity loads, it will create a newstatic TestObject with id "12345". When the save button is clicked the followingmethod 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 eithersuccessful 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 3instantiates an instance of TestObject for the library into which the data is loadedfrom the backend. And lines 4 through 23 load the object and display an alert if theload is either successful or fails. 25
  28. 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. 29. Written byMorgan Bickle Randall CronkOn any given day youll find Morgan Since 1990, Randall has helped over 250programming mobile SDKs, building high-tech companies convey the valuebackend APIs, and discussing the future of what they do through white papers,of web and mobile technology. As part of web content, brochures, case studiesthe core founding team at Kinvey and and articles. Based today in downtownnow the CTO, he owns Kinvey’s Boston, he was previously a vicetechnology vision. Prior to Kinvey, he president with Regis McKenna where hewrote enterprise software for a decade. ran the Digital Equipment account.Designed byJake 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 its free to get started and you only pay when your app is successful. Build your backend today

×