Ch 2: Getting Started Flashcards
What you need to start developing
Android applications
- Android Software Development Kit(SDK)
- Java Development Kit (JDK)
- An Integrated Development Environment(IDE)
- Android Studio is strongly suggested
Android Studio:
Overview
- Google’s officially supported IDE for Android app development
- Includes an integrated JDK and manages installation of Android SDK and associated tools
- Purpose built for Android development
- Built on top of IntelliJ IDEA
- Supports all Android Form Factors
- Includes tools for:
- rich code editing
- debugging
- testing
- profiling
- version control
Programming Languages
for Android
Can be written in either Java or Kotlin
- Java
- Statically typed
- Kotlin
- Statically typed language
- Fully interoperable with Java source files and Android Run Time
Benefits of Kotlin
- Fully interoperable with Java source files and Android Runtime
- Considered expressive and concise
- Introduces improvements:
- reduced language verbosity
- null-pointer safety
- extension functions
- infix notation
Java is still the default, but Kotlin is expected to become very popular
Kotlin:
Extension Functions
- Allow you to extend a class with new functionality, without having to create a new subclass or use design patterns such as a Decorator
- Can write a new function for a class without modifying the class code
- There are also Extension Properties that work similarly
- Syntax:
- Define a new function, appended to the class name
- fun <classname>.<myfunction>(...parameters){ .... }</myfunction></classname>
- Define a new function, appended to the class name
Kotlin:
infix notation
- Allows functions to be called with just their name
- Similar to core functions like arithmetic
- Defined by using the infix keyword before a function definition:
- infix fun myFunc(x: Int) { …. }
- Used simply with the class/object and the name of the function:
- this myFunc 5
- Rather than: this.myFunc(5)
- Function must meet some requirements:
- Be a member function or extension function
- Single parameter
- Parameter must not accept variable number of arguments(no lists, etc)
- No default value for the parameter
Android SDK Manager:
Overview
- Integrated into Android Studio
- Manages installation of Android SDK components, tools, Framework Libraries and optional add-ons
Unique Challenges of
Mobile Development
- Small Form Factors
- Limited Battery Life
- Restricted Processing Power
- Restricted Memory
- Unreliable Network Connections
- Increased need for Responsiveness
- User Interface must be simple and easy to learn
Android Studio:
Major IDE Features
- Intelligent code editing:
- Advanced code completion
- Refactoring
- Code analysis
- Version control integration including GitHub and Subversion
- Robust static analysis framework:
- Over 280 Lint checks along with quick fixes
- Extensive testing tools and frameworks:
- JUnit 4
- Functional UI tests
- Tests can be run on :
- Device
- Emulator
- Continuous Integration Environment
- Firebase Test Lab
Android Studio:
Useful Build and Debug Features
- Android Project Wizard
- XML Editors
- Automated Build Process:
- Build Project
- Convert to Android exectuable (.dex)
- Creating package files (.apk)
- Installation of packages onto Android Run Time
- Android Virtual Device manager
- Android Emulator
- Access to Emulator filesystem
- Android Profiler
- Runtime debugging
- Logging and console outputs
Android Studio:
Basic Things
you should know how to do
- Create a new Project
- Create Android Virtual Device
- Configure a Physical Device for Testing and Debugging
- Run and Debug Android Application
Android Studio:
Creating a New Project:
Basic Steps
- Open New Project Wizard
- File->New->New Project
- Select a Project Template
- Select Form Factor (Target Device)
- Select a main Activity
- Configure:
- Name
- Directory
- Package
- Android SDK version
Android Studio Operations:
Create an Android Virtual Device
steps
- Open AVD Manager
- Tools->AVD Manager
- Click “Create Virtual Device” button to open Virtual Device Configuration dialog box
- Choose a Hardware Profile from the list (can also create or import)
- Select System Image
- Android API version
- Application Binary Interface(ABI) - usually x86 or ARM
- May need to download the desired system image
- Give the AVD a descriptive name and a startup orientation
- Also some more advanced settings here
- Finish
Android Studio Operations:
Configure a Physical Device
Steps
- Enable Developer Mode on the device
- On device, go to: Settings->About->Build Number
- Tap “Build Number” 7 times
- There will now be an option under Settings called “Developer Options”
- Go to it, enable “USB Debugging”
- Connect the Device to the Development Computer using a USB cable
- Give permission to allow USB Debugging on the Dialog Box that comes up
- The device will now be available as a target when attempting to Run or Debug the App in Android Studio
- (As long as it is plugged in on USB)
Project Wizard:
Available Form Factors
and
Project Templates
-
Phone and Tablet
- Templates: See dedicated flashcard
-
Wear OS
- Watch Face
- Google Maps Wear Activity
- Blank Wear Activity
-
Automotive
- Media Service
- Messaging Service
-
TV
- Android TV Activity
-
Android Things
- Android Things Empty Activity
Project Wizard:
Phone and Tablet
Project Templates
(12)
- Basic Activity
- Empty Activity
- Fragment + View Model
- Bottom Navigation Activity
- Fullscreen Activity
- Master/Detail Flow
- Navigation Drawer Activity
- Google Maps Activity
- Login Activity
- Scrolling Activity
- Tabbed Activity
- Native C++
Android Studio Operations:
What happens “behind the scenes”
when Running or Debugging
- Current Project souce is compiled to byte code
- bytecode is then converted to an Android executable (.dex)
- Package Created:
- Executable, Resources and Project Manifest are put into an Android Package(.apk)
- Deploys Package to device and installs it
- If using AVD and it is not running, the AVD is started first
- Starts the application
- If debugging, the Android Studio debugger is also attached to allow for setting breakpoints and debugging
Android Projects:
Project Hierarchy
-
/app - The main folder for the application
-
/manifests - Lists of things included in the project
- AndroidManifest.xml
- /java - class definitions, our source code
- /java (generated) - generated code, including build configurations
-
/res - Resources used in the application
- /drawable
- /layout
- /menu
- /mipmap
- /values
-
/manifests - Lists of things included in the project
Android Sample Projects:
Basics
- Well documented sample projects included with Android Studio
- Projects are hosted on Git Hub
- Accessed through the Import Sample Wizard
- Use File -> New -> Import Sample
Android Support Library:
Overview
- Also referred to as the “compatibility library” or AppCompat
- A set of libraries that you can include as part of a project
- Acess Convenience APIs that aren’t part of the framework
- Access useful APIs not available on all platform releases
- Updated more regularly than the Android framework SDK
Android Support Library:
Using a Package in your Project
- Use SDK Manager to ensure the Android Support Repository is downloaded
- Add dependency for the package to the Gradle Build
- Add to Module level Gradle Build file (module:app build.gradle), in the “dependencies” block:
- implementation <package></package>
- Alternatively, Add using Android Studio’s Project Structure UI
- Add to Module level Gradle Build file (module:app build.gradle), in the “dependencies” block:
Developing for Mobile and Embedded Devices:
Challenges of Mobile Devices
- Low processing power
- Limited RAM
- Limited Storage capacity
- Small Screens
- High costs associated with data transfers
- Network issues:
- Intermittent connectivity
- Slow data transfer rates
- high latency
- Limited battery life
Developing for Mobile and Embedded Devices:
Design Tips
- Prioritize Performance
- Expect Limited Storage Capacity
- Design for Different Screens and Form Factors
- Expect Low Speeds and High Latency
- Save Battery Life
Developing for Mobile and Embedded Devices:
Design Tips:
Performance Matters
- In embedded and mobile devices, thinner form factors and bigger screens are valued more than performance
- Software developers cannot count on performance increases from Moore’s Law like they can with desktop computers
- Code should be optimized so that it runs quickly and responsively
Developing for Mobile and Embedded Devices:
Design Tips:
Expected Limited Storage Capacity
- Although many devices have quite a bit of storage, lower end devices do not
- Most available storage on a device will be used to store photos, music and movies
- Users are likely to uninstall apps that take up too much memory
- Application install size should be limited
- Application should be polite in its use of system resources
Developing for Mobile and Embedded Devices:
Design Tips:
Expected Limited Storage Capacity:
Techniques for limiting memory usage
- Use Android databases to persist, reuse and share large quantities of data.
- Used existing optimized frameworks for Files, Preferences and State information
- Clean up after yourself:
- caching, pre-fetching, and lazy loading are useful for limiting repetitive network lookups and improving responsiveness
- Don’t leave files on filesystem or records in a database when they’re no longer needed
Developing for Mobile and Embedded Devices:
Design Tips:
Design for Different Screens and Form Factors
- Small size and portibility are a challenge for creating good interfaces
- Applications should be intuitive and easy to use:
- Reduce number of controls
- Put most important info front and center
- Prioritize Graphical controls
- Consider how touch input will affect the interface design
- Consider how to support accessibility and non-touch screen devices such as TVs
- Create responsive designs and test application on a variety of screens
- Ensure UIs scale well
Developing for Mobile and Embedded Devices:
Design Tips:
Expect Low Speeds, High Latency
- Internet connectivity is not as fast, reliable, cheap, or readily available as we would like.
- It is best to assume a network connection will be slow, intermittent, expensive and unreliable
- App should be able to handle losing, or not finding, a data connection
- Techniques:
- Limit functionality of app
- Reduce network lookups to cached bursts when data transfer capabilities are limited
Developing for Mobile and Embedded Devices:
Design Tips:
Save Battery Life
- Battery life is a significant problem
- Larger, higher resolution screens and thinner form factors make it worse
- Network Data Transfers are one of the most dramatic influencers
- Carefully consider if and when you choose to transfer data
- Useful APIs for conserving battery life:
- Doze
- App Standby
- Job Scheduler
Considering User’s Environment:
How people use Smart Phones
- Your application is unlikely to be the most important App on a user’s phone
- Typical Usage Priority:
- Communications device
- Camera
- Music and Video Player
- Games
- “Useful Stuff” (your app)
- People use their phones in many different environments
Considering User’s Environment:
Software design should make the app:
- Predictable and well behaved
- Switch seamlessly from background to foreground
- Polite
- Present an attractive and intuitive UI
- Be responsive
Developing for Android:
High Quality design considerations
according to Android Design Philosophy
- Performance
- Responsiveness
- Freshness
- Security
- Seamlessness
- Accessibility
Developing for Android:
Being Performant
Two Basic Rules:
- Don’t do work that you don’t need to do
- Don’t allocate memory if you can avoid it
System memory is a scarce commodity, take special care to use it efficiently.
Think about:
- how you use the stack and heap
- limiting object creation
- being aware of how variable scope affects memory use