Download - Android development first steps
Christoforos Nalmpantis Software Engineer and Tech
Entrepreneur Co-Founder of Neighbourfood
Founder of Coeus Labs
Loyds Banking Group
Powa Technologies
BusuuWhat Now Travel
The App Business
Agenda
• Working as an Android Engineer in London
• What is Android
• Think "mobile"
• Tools in Android Development
• Android Development lifecycle
• Basic components
• Acitivity lifecycle - demo
• My first app
Working as an Android Engineer in London
• Opportunities
• Big tech companies: Google, Amazon, Facebook, Yahoo, (Apple?) etc
• Start ups (SwiftKey, CityMapper, Busuu)
• Finance, Games, Enterprise etc
• Interview process: Algorithms, Data structures, Design patterns, Android framework, Java
• Salary expectations 25k - 90k (£1,673 - £4,960)
• Big events, conferences, many meetups, interesting people, startup spirit
Android History
• Android, Inc. was founded in Palo Alto, California in October 2003, by Andy Rubin, Rich Miner, Nick Sears and Chris White.
• Android was intended for digital cameras.
• Google acquired Android Inc. on August 17, 2005.
• At Google, the team led by Rubin developed a mobile device platform powered by the Linux kernel.
Android is a software stack
• Linux Kernel - low level tasks
• Libraries in C C++ (e.g. sqlite) and Android runtime (e.g. Android virtual machines, Dalvik and more recently ART.
• Application Framework - Your apps run within its own instance of the VM using the classes and services provided here.
• Applications - Includes your app and all apps installed on the device.
Lollipop
• Material design: fluid, purposeful motion
• Notifications: respond directly from your lock screen.
• Battery: feature that extends your device by up to 90 minutes
• More ways to secure your device: multiple user accounts, guest mode, android smart lock.
• Even more devices: phones, tablets, wear, tv, auto, one.
Start thinking like a mobile developer.
• Object Oriented Programming (OOP)
• Java
• Smartphones = small computers
• User Experience (UX) is very important.
• Mobile OS is an ecosystem of many Apps
Key mobile challenges
• Low processing power
• Limited RAM
• Intermittent, low bandwidth, high latency data connections
• Impact on battery
• (Android?) Fragmentation
• Support multiple devices
What happens when you run an app in Android Studio?
Android Project Build Resources
Manifest
Byte Code
SignInstall
on device
n
Tools used in Android development.
• Android Studio
• Gradle
• Genymotion
• SDK Tools
• Version control system (git)
• Continuous Integration tools (Jenkins)
Gradle
• From command line to Ide to continuous integration
• Declare and execute all tasks necessary to compile, test, package and ship.
• Support multi-language, multi-platform, multi-project and multi-channel software, Saas and mobile apps
A faster Android emulator
Genymotion is the next generation of the AndroVM open source project, already trusted by 2,500,000 developers. It’s even easier to use and offers lots more features.
Android SDK Tools
adb
android
AVD Manager
bmgr
Device Monitor
dmtracedump
Draw 9-Patch
Emulator
etc1tool
hprof-conv
jobb
lint
logcatmksdcard
ProGuard SDK Manager
Tracer for OpenGL ES
Traceviewzipalign
Git
• Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
• UI client for git -> SourceTree
• The Gitflow Workflow defines a strict branching model designed around the project release.
–Manifesto for Agile Software Development
“Customer Collaboration over Contract negotiation”
“Working Software over Comprehensive Documentation”
“Individuals and Interactions over Processes and tools”
“Responding to change over Following a plan”
Basic Android Components
Activities An Activity represents a single screen with a user interface
ServicesA service is a component that runs in the
background to perform long-running operations or to perform work for remote processes.
Content Providers
A content provider manages a shared set of app data.
Broadcast Receivers
A Broadcast receiver is a component that responds to system-wide broadcast announcements.
The Manifest File
• Android system must know that the component exists by reading the app’s AndroidManifest.xml file.
• Identify any user permissions the app requires.
• Declare the minimum API level required by the app.
• Declare hardware and software features used or required by the app (e.g. camera, bluetooth services).
• Other than Android framework APIs (Google maps library).
• And more.
Views and ViewGroups
• A View is the basic UI component.
• Buttons, TextViews, ImageViews and other are all subclasses of View.
• ViewGroup is also subclass of a View, and can contain many views.
• Layouts are subclasses of ViewGroup ( LinearLayout, RelativeLayout, FrameLayout).
• To convert Layouts to Java objects we need to inflate the layout.
• To use our views in Java we need to find the views after inflating the layout which contains them.
Activity Lifecycle
• onCreate(Bundle savedInstanceState)
• onStart()
• onResume()
• Now the activity is visible and the user can interact with it!
Activity Lifecycle
• onPause()
• onStop()
• Now the app is not visible! (these are images not real views)
Activity Lifecycle
• onRestart()
• onStart()
• onResume()
• Now the activity is visible again and the user can interact with it!
Activity Lifecycle
• onPause()
• Now the activity is partial visible! This is a technical term and means that the activity is on Pause() because a dialog is shown. The user cannot interact with the UI of our activity anymore.
Activity Lifecycle
• onResume()
• Now the activity is visible again and the user can interact with it!
Activity lifecycle states
• Entire Lifetime: This is the lifetime between the first call to the onCreate() and the final call to onDestroy() method. We create all global resources such as screen layout, global variables etc in onCreate() and release all resources with onDestroy() call.
• Visible Lifetime: It is the lifetime of an Activity between onStart() and onStop() method calls. In this the Activity is visible to the user and he may or may not be able to interact with it. During the visible lifetime, an Activity maintains its state intact.
• Foreground Lifetime: Foreground lifetime starts with onResume() and ends with onPause() method calls. During this, the Activity is completely visible to the user and is on top of all other Activities so that user can interact with it.
My first Android App
• Collect requirements
• Start development process
• Test
• Iterate again until the app is ready for release.
• Maintain the app and add new features using the previous steps.
Break the project into small user stories
• As a user I want an android app.
• As a user I want the app to show images from london.
• As a user I want the images to be shown in a list view.
• As a user I want the listview to support infinite images and scroll smoothly.
• As a user I want to tap on an image and show it in full screen.
Analyse requirements
• Which components do we need?
• 2 screens -> 2 Activities
• 2 screens + 1 imageItem -> 3 Layouts
• List of images -> RecyclerView
• Show data in list -> Adapter
• Items of images -> ViewHolder
• Load images from Internet -> Picasso
START CODING!!!
ScrollView<?xml version="1.0" encoding=“utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ImageView android:id="@+id/item_image_imageView" android:layout_width="match_parent" android:layout_height="@dimen/image_size" android:scaleType="centerCrop" /> <ImageView android:layout_width="match_parent" android:layout_height="@dimen/image_size" android:scaleType="centerCrop" /> <ImageView android:layout_width="match_parent" android:layout_height="@dimen/image_size" android:scaleType="centerCrop" /> . . . </LinearLayout> </ScrollView>
If you have 100 images in the list and can fit 3 items on screen at once - what is the minimum number of views you need to create to scroll through the list?
1. one2. three3. four4. five5. ten6. one hundred
ListView
• Request a view for every visible item.
• Create two more for both directions ( up/down) to avoid flickering of the screen as a new view is created and populated.
• As you scroll more views are added to memory
RecyclerView
• Request a view for every visible item.
• Create two more for both directions ( up/down) to avoid flickering of the screen as a new view is created and populated.
• As you scroll, the views going off the screen are recycled and reused for the new views, by just populating the new data.
• Less memory overhead, smoother scrolling and less view management.
Useful links
• Speakers linkedn profile: https://uk.linkedin.com/pub/christoforos-nalmpantis/44/231/23
• Activity lifecycle demo source code: https://github.com/ChristoferNal/activityLifecycle
• PracticeRecyclerVIew source code: https://github.com/ChristoferNal/practiceRecyclerView/tree/develop