Introduction to Android Software Development T-110.5130 Mobile Systems programming Juha-Matti Liukkonen juha-matti.liukkonen@reaktor.com Introduction to Android Software Development 1. Introduction to Android 2. Development Tools 3. Interlude: The Design Step 4. Key Android Concepts 5. Putting Your App Together 6. Where to go next Introduction to Android World’s most popular mobile operating system Android = Linux • Linux kernel • Most Android specific mechanisms now included in mainstream Linux kernel – wakelocks, binder, etc • Custom startup script mechanism • A simple, classic init.rc script solution • (Generic) applications written in Java • Applications do not need to care about underlying processor capabilities • Custom Java runtime (actually 2: Dalvik, Android RunTime) • Optimized for low footprint = suitable for mobile devices 1.400.000.000 users • In 2015, 82% of new smartphones ran Android • 1.4 billion users, 1.5 million new devices activated every day • 54% total market share (and obviously rising) • 78% of Chinese market • 70% of tablet market • 4000+ different device models • 400+ device manufacturers • Also used in wearables, TVs and cars • Small segments so far Most devices are never updated Main versions: 6.0 2015 4.4W (watch) 2015 5.x 2014 4.4 2014 4.x 2012-2013 4.0 2011-2012 3.0 2011 2.x 2010 Many screen sizes, form factors Also – different interaction models! Variety pros & cons • Con: your software will not work properly on most Android devices • Choose your target devices wisely to reach your targeted users! • Customized layouts, graphics, interaction models needed to support different device types • Some handled via Play Store device filters, some by app manifest tags, some by resources, some you need to handle in your code • Pro: the same programming model works on all Android devices • If you know how to create software for an Android phone, you also know how to do it for tablets, smartwatches, cars and TVs Takeaway • Android is basically Java on Linux • It’s easy to reach gazillions of users with Android apps • Variety makes it hard to write good Android apps Development Tools What you need to get your app done The good and the bad news • Android Studio contains everything you need (yay 2016!) • …just that it usually doesn’t contain it by default • For very simple apps, only for latest devices, defaults are OK • So, after Android Studio installation, remember to: • Configure -> SDK Manager • Install the Android versions you want to build software for • Also advisable to install the most common support libraries Getting ready to do software • Press ”OK” – now your environment is set up • Android Studio will generate application skeletons for common application types for you • All you need to do is …”fill in the details” Now things get interesting • What to choose as Activity? • What does your software actually need to do? • This is the stage when we usually do… Interlude: The Design Step The critical step before actually writing any software (nothing to do with Android as such) Understand your use case • What problem does your app solve? • For whom? (Concrete example, no abstract persons!) • In which situation does the problem occur? • How does the user launch your app in that situation? • How does your app fulfill the user’s need? Example: Adhoc Ideas • Problem: helping ad-hoc ideas be stored (eg. app ideas!) • User: my colleague Antti (will use him for testing) • Where: in public transport, during work commutes (noisy environment so audio recording isn’t polite & doesn’t work) • Launch: shortcut icon on home screen • Fulfillment: it’s easy to write free-form text immediately Identify & prioritize features 1. Open up, instantly ready for writing 2. Autosave entered text 3. Multiple notes can be saved 4. Any saved note can be opened up for reading 5. Any saved note can be emailed 6. Any saved note can be deleted 7. Bold and italic text 8. Email recipients can be taken from the address book 9. … This is clearly our priority #1 – if the app has this feature, it is already useful to Antti Draft the user interface • Pen and paper are good – low cost, quick iterations • Build a runnable app from your doodles using POP • Online wireframe apps also available: Fluid, InDesign • Test your design with a real user! • Clickable prototype (POP, Fluid, InDesign) or just flip paper pics • Is your assumption about the need valid? • Is your assumption about the 1st feature workflow valid? Incremental design • Split non-trivial features into clear workflow steps • Design the simplest possible implementation for each step • Think how each step can be improved later on (if needed) • Implement the simplest variant end-to-end • Now go test it with the real user – what’s the user’s priority, which step would benefit most from an improvement? • Does the user benefit more from an improvement to the existing minimal workflow, or from a new feature? User story slicing By Arto Eskelinen, see slideshare.com Takeaway • Think about your app before coding it • Test your concept with a real user • Paper or wireframe apps are good for getting feedback • Implement something simple end-to-end first, add complexity later, when it has value Key Android Concepts What you need to know about Android app structure Intents launch Activities • Each screen with a user interface is an Activity • A note writing screen, a list of notes, app settings, … • The user is focused on doing one thing • A component in your app implements one Activity • Your app usually has multiple Activities (so, also multiple components) • Components invoke other Activities using Intents • Simply pass an Intent object to startActivity() • Activities in other apps can also be invoked – for example, viewing web pages can invoke Activity in the browser app • Your app can publish any Activity it implements via its manifest file Non-interactive activities • A Service is a component running in the background • Playing music, fetching data, mining bitcoin, etc. • Another component can use bindService() to interact with it • A ContentProvider is a shared data manager • A music library, text notes, search results etc. • Rich API inherited from the ContentProvider class • A BroadcastReceiver listens for system state changes • Battery low, network connection lost, memory low, etc. • May eg. trigger autosave, show an icon in status bar, lock the screen Declaring public activities This is the application manifest XML file, generated by Android Studio for you Filtering Intents you can serve Declaring your requirements Devices that don’t fulfill your manifest requirements can’t even install the app from Play Store. Non-code elements • Resources = images, view layout, localization text, etc. • Stored under the res/ subdirectory in your app • Drawables (= images) in res/drawables/ • Localized files in res/subdirectory-languagecode/ • You can provide different layouts & images for different device types • Provide resource file variants for different resolutions, aspect ratios and localizations • The system automatically chooses the best matching resources Putting Your App Together Making it all work and run on your device Getting to the beef • You have validated your app concept with the user? • You have chosen your first feature? • You have tested your wireframe mockup with the user? • You have some idea about Activities, Intents, the manifest file, and resources? • You have installed Android Studio? • Good: then let’s get back to ”Start a new Project”… let’s click it all together! Give your app a name here Now you need to decide which device types and versions to support… Several template Activities are available. We’ll build our own so choose Empty! MainActivity is a good name, just click Finish! This skeleton is automatically generated for us Click on the left at 1:Project to find all the elements of your app The manifest maps the Launcher’s start-up action (”MAIN”) to your MainActivity Now select your layout, the device view appears to the right. Here is the layout object. Select and delete the default TextView When done, press Play! Drag the Multiline Text from the widget palette on top of your RelativeLayout and resize to fit screen. Selecting the device to run on • If you have a real Android device • Enable Developer Mode in the Android Settings app • In 4.2+, go to About device, tap Build Number 7 times (really!) • Connect it to your PC/Mac with a USB cable • Select the device from the pop-up that appears after Play • If you don’t • Select emulator, and choose the device type to emulate • Note: it’s a good idea to test on all device variants you wish to support, so you may want to use the emulator for other types even if you have some real device The Adhoc Ideas app, 1st priority feature ready for user testing! Multitasking, limited autosave, etc provided by system. Drag a button to your Layout, give it a label Resize the UI elements to fit The editor will help you add the imports Write a function to implement desired behavior (e.g. send email) In layout view, select the button, then select your new function as its onClick event handler Next steps • Adding useful functionality • Advertisements!, billing per-typed-letter, … • Plenty of useful APIs available in Google Services library • Making it pretty and natural to use • Study the Google Material Design guidelines • Add drawable resources to have image backgrounds etc • Optimizing UI layout for different device types • Create resolution specific layout XML files • Remember resolution variants of your drawables Where to go next Where to find additional information First place to visit This is the treasure trove Start from Training or API Guides, also do look at the Design page Developer Reference is where most Android developers spend their days… This is where you get to distribute and sell your app via the Play Store! Thank You! Juha-Matti Liukkonen juha-matti.liukkonen@reaktor.com