SlideShare a Scribd company logo
Android Development Best
Practices. Android Wear
by Yuriy Voznyak, Software Engineer
eleks.com
You can view the presentation on http://eleksdev.blogspot.com
1
Android Wear
OS for SmartWatches and wearable devices
2
How to pair with?
● Install the Android Wear app
● Tap “Pair with a new watch”
● Tap “Enable Notifications”
Some Wear devices can be
paired with iOS
3
What systems have in common?
Android Wear and Android have common API. Except:
● No WebView in Wear;
● No direct internet connection: use Data Layer API
instead;
● No print subsystem;
● No cloud backup subsystem;
● No application widgets (e.g. on Launchers);
● No interaction with USB devices.
4
How to Show Notifications
Do nothing :) all Push Notifications appear
on Wear. Or customize notifications with
Wear extensions:
5
● User can interact with Wear notifications via Pending
Intent;
● Notifications on Wear can be customized;
● Show only wearable notification, not on handheld;
● Set custom backgrounds.
Distributing Wear apps
When publishing to users, you must package a wearable
app inside of a handheld app, because users cannot
browse and install apps directly on the wearable. If
packaged properly, when users download the handheld
app, the system automatically pushes the wearable app to
the paired wearable.
While developing, installing apps with adb install or
Android Studio directly to the wearable is required.
6
Defining Layouts
Specify Different Layouts for Square and Round Screens
<android.support.wearable.view.WatchViewStub
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/watch_view_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rectLayout="@layout/rect_activity_wear"
app:roundLayout="@layout/round_activity_wear">
</android.support.wearable.view.WatchViewStub>
7
Accessing layout views
The layouts that you specify for square or round screens are not inflated until WatchViewStub
detects the shape of the screen, so your app cannot access their views immediately. To access
these views, set a listener in your activity to be notified when the shape-specific layout has been
inflated:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wear);
WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override public void onLayoutInflated(WatchViewStub stub) {
TextView tv = (TextView) stub.findViewById(R.id.text); // Now you can access views
...
}
});
}
8
Also You Can
● Design new Watch Faces;
● Work with built-in speakers into
Wearables;
● Debug over Bluetooth;
● Send and collect data via Sync
mechanism;
● … And much much more.
9
Best Practices: Useful Libraries
● Gson;
● EventBus;
● ButterKnife
● Dagger 2
● Glide
● DBFlow
10
GSON
Gson is a Java library used for serializing and deserializing Java objects
from and into JSON. A task you will frequently need to do if you
communicate with APIs. JSON is recommended to use because it’s
lightweight and much simpler than XML.
// Serialize
String userJSON = new Gson().toJson(user);
// Deserialize
User user = new Gson().fromJson(userJSON, User.class);
Gson works great with Retrofit as serializer/deserializer.
See more on https://github.com/google/gson
11
EventBus
EventBus is a library that simplifies communication between different parts of your
application. For example, sending something from an Activity to a running Service,
or easy interaction between fragments.
EventBus is an Android optimized publish/subscribe event bus. A typical use case
for Android apps is gluing Activities, Fragments, and background threads together.
Conventional wiring of those elements often introduces complex and error-prone
dependencies and life cycle issues. With EventBus propagating listeners through all
participants (e.g. background service -> activity -> multiple fragments or helper
classes) becomes deprecated. EventBus decouples event senders and receivers
and thus simplifies communication between app components. Less code, better
quality. And you don't need to implement a single interface!
12
EventBus Example
public class HomeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EventBus.getDefault().register(this); // register EventBus
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this); // unregister EventBus
}
public void onEventMainThread(NetworkStateChanged event) {
if (!event.isInternetConnected()) {
Toast.makeText(this, "No Internet connection!", Toast.LENGTH_SHORT).show();
}
}
}
public class NetworkStateChanged {}
EventBus.getDefault().post(new NetworkStateChanged());
See more on http://greenrobot.org/eventbus/
13
Butterknife
A library for binding Android views to fields and methods (for instance, binding a view OnClick to a
method). Annotate fields with @Bind and a view ID for Butter Knife to find and automatically cast
the corresponding view in your layout.
class ExampleActivity extends Activity {
@BindView(R.id.title) TextView title;
@BindView(R.id.subtitle) TextView subtitle;
@BindView(R.id.footer) TextView footer;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
// TODO Use fields...
}
}
See more on http://jakewharton.github.io/butterknife/
14
Dagger 2
15
Dagger is a fully static, compile-time dependency injection framework for both Java
and Android. It is an adaptation of an earlier version created by Square and now
maintained by Google. Dagger creates instances of your classes and satisfies their
dependencies. It relies on javax.inject.Inject annotation to identify which constructors
or fields should be treated as dependencies.
Dagger 2 is the successor of the famous Dagger dependency injection library. One of
the major improvements is using zero reflection in generated injection code, which
makes debugging a lot easier.
Dagger 2 is the first to implement the full stack with generated code. The guiding
principle is to generate code that mimics the code that a user might have hand-written
to ensure that dependency injection is as simple, traceable and performant as it can
be.
Dagger Code Example
class Thermosiphon implements Pump {
private final Heater heater;
@Inject
Thermosiphon(Heater heater) {
this.heater = heater;
}
...
}
class CoffeeMaker {
@Inject Heater heater;
@Inject Pump pump;
...
}
16
Also allows to resolve dependencies;
Build the dependencies Graph; Resolve
constructors as Singletons; Lazy
Injections; Compile-time validation and
much much more.
Read more on
http://google.github.io/dagger/
Glide
Glide is the library to use for loading images. Current alternatives are Universal Image Loader
and Picasso.
Glide is recommended by Google.
Here's a simple example how you can use Glide to load an image from a URL into ImageView:
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);
See more on https://github.com/bumptech/glide/wiki
17
DBFlow
The Fastest Android ORM Database Library
DBFlow uses Annotation Processing functionality to generate all sorts of classes and
interactions with the database at compile time. This enables the library to run at native speed
and becomes as fast as writing the code yourself. Also, generating code is transparent–we can
see the code that the app executes and catch errors at compile time. Reflection is difficult to
debug, since we will only catch errors at runtime.
List devices = new Select().from(DeviceObject.class)
.where(
Condition.column(DeviceObject$Table.NAME).is("Samsung-Galaxy-S5"),
Condition.column(DeviceObject$Table.CARRIER).is("T-Mobile")).queryList();
Delete.table(DeviceObject.class);
See more on https://github.com/Raizlabs/DBFlow
18
It is only small amount
Think about using libraries!
19
Gradle
● Build different flavours or variants of your app
● Make simple script-like tasks
● Manage and download dependencies
● Customize keystores
● And more
20
Maven Dependencies for Gradle
The main reason is not to keep the library locally as Jar or something else
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Or
dependencies {
compile 'org.hibernate:hibernate-core:3.6.7.Final'
} 21
IDE
Use Android Studio
Eclipse is deprecated since 2015
22
Components and UI
● Avoid using nested layouts; Avoid deep hierarchy for
views
● Use styles instead of views spot customization;
● Don`t put much code to Activities or Fragments;
● Dont`use Intents for in-application communication. Use
RxJava or EventBus if possible;
● Don`t rely on Android System-level intents.
23
ProGuard
ProGuard is a tool for code obfuscation, shrinking and
optimization
● Use it;
● Verify Release builds for ProGuard rules;
● Keep mapping.txt for every release.
24
Naming Convention
Naming Convention Must Be!
Bad naming convention is better than no convention
25
Useful Links
● https://github.com/futurice/android-best-practices
● https://developer.android.com/guide/practices/index.html
● https://developer.android.com/training/best-performance.html
● https://developer.android.com/training/best-ui.html
● http://www.innofied.com/13-android-development-best-practices/
● https://github.com/ribot/android-
guidelines/blob/master/project_and_code_guidelines.md
● https://google.com
26
It`s Questions Time
Find us at eleks.com Have a question? Write to eleksinfo@eleks.com
27
Inspired by Technology.
Driven by Value.
Find us at eleks.com Have a question? Write to eleksinfo@eleks.com
28

More Related Content

What's hot

Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Purbarun Chakrabarti
 
Mongo db
Mongo dbMongo db
Mongo db
Gyanendra Yadav
 
Selenium Java for Beginners by Sujit Pathak
Selenium Java for Beginners by Sujit PathakSelenium Java for Beginners by Sujit Pathak
Selenium Java for Beginners by Sujit Pathak
Software Testing Board
 
BDD using Cucumber JVM
BDD using Cucumber JVMBDD using Cucumber JVM
BDD using Cucumber JVM
Vijay Krishnan Ramaswamy
 
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
eleksdev
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
Antoine Sabot-Durand
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
Hamid Ghorbani
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applications
qooxdoo
 
Advanced java
Advanced java Advanced java
Advanced java NA
 
A Taste of Java ME
A Taste of Java MEA Taste of Java ME
A Taste of Java MEwiradikusuma
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
Mohit Gupta
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
Mohit Belwal
 
Selenium using C# by Yogesh Kumar
Selenium using C# by  Yogesh KumarSelenium using C# by  Yogesh Kumar
Selenium using C# by Yogesh Kumar
Software Testing Board
 
SpringBoot
SpringBootSpringBoot
SpringBoot
Jaran Flaath
 
Spring Framework 5.0: Hidden Gems
Spring Framework 5.0: Hidden GemsSpring Framework 5.0: Hidden Gems
Spring Framework 5.0: Hidden Gems
VMware Tanzu
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
Oleg Tsal-Tsalko
 
Mvvw patterns
Mvvw patternsMvvw patterns
Mvvw patterns
eleksdev
 
Java Development EcoSystem
Java Development EcoSystemJava Development EcoSystem
Java Development EcoSystemAlex Tumanoff
 

What's hot (20)

Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Mongo db
Mongo dbMongo db
Mongo db
 
Selenium Java for Beginners by Sujit Pathak
Selenium Java for Beginners by Sujit PathakSelenium Java for Beginners by Sujit Pathak
Selenium Java for Beginners by Sujit Pathak
 
BDD using Cucumber JVM
BDD using Cucumber JVMBDD using Cucumber JVM
BDD using Cucumber JVM
 
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applications
 
Advanced java
Advanced java Advanced java
Advanced java
 
Maven
MavenMaven
Maven
 
A Taste of Java ME
A Taste of Java MEA Taste of Java ME
A Taste of Java ME
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
 
Selenium using C# by Yogesh Kumar
Selenium using C# by  Yogesh KumarSelenium using C# by  Yogesh Kumar
Selenium using C# by Yogesh Kumar
 
SpringBoot
SpringBootSpringBoot
SpringBoot
 
Spring Framework 5.0: Hidden Gems
Spring Framework 5.0: Hidden GemsSpring Framework 5.0: Hidden Gems
Spring Framework 5.0: Hidden Gems
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
Mvvw patterns
Mvvw patternsMvvw patterns
Mvvw patterns
 
Java Development EcoSystem
Java Development EcoSystemJava Development EcoSystem
Java Development EcoSystem
 

Similar to Lecture android best practices

Visage Android Hands-on Lab
Visage Android Hands-on LabVisage Android Hands-on Lab
Visage Android Hands-on Lab
Stephen Chin
 
Griffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java TechnologyGriffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java Technology
James Williams
 
Android presentation
Android presentationAndroid presentation
Android presentationImam Raza
 
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
Hazem Saleh
 
Apache Cordova In Action
Apache Cordova In ActionApache Cordova In Action
Apache Cordova In Action
Hazem Saleh
 
Building Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsBuilding Cross-Platform Mobile Apps
Building Cross-Platform Mobile Apps
Troy Miles
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Visage Android Hands-on Lab (OSCON)
Visage Android Hands-on Lab (OSCON)Visage Android Hands-on Lab (OSCON)
Visage Android Hands-on Lab (OSCON)
Stephen Chin
 
GUI design using JAVAFX.ppt
GUI design using JAVAFX.pptGUI design using JAVAFX.ppt
GUI design using JAVAFX.ppt
TabassumMaktum
 
Lecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxLecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptx
GevitaChinnaiah
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
Chiew Carol
 
Spring boot
Spring bootSpring boot
intoduction to Grails Framework
intoduction to Grails Frameworkintoduction to Grails Framework
intoduction to Grails Framework
Harshdeep Kaur
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
Aishura Aishu
 
From React to React Native - Things I wish I knew when I started
From React to React Native - Things I wish I knew when I startedFrom React to React Native - Things I wish I knew when I started
From React to React Native - Things I wish I knew when I started
sparkfabrik
 
Lezione 03 Introduzione a react
Lezione 03   Introduzione a reactLezione 03   Introduzione a react
Lezione 03 Introduzione a react
University of Catania
 
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
Hazem Saleh
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
Matteo Manchi
 
Installing eclipse & sdk
Installing eclipse & sdkInstalling eclipse & sdk
Installing eclipse & sdkArun Kumar
 
Top Ten Tips for HTML5/Mobile Web Development
Top Ten Tips for HTML5/Mobile Web DevelopmentTop Ten Tips for HTML5/Mobile Web Development
Top Ten Tips for HTML5/Mobile Web Development
Simon Guest
 

Similar to Lecture android best practices (20)

Visage Android Hands-on Lab
Visage Android Hands-on LabVisage Android Hands-on Lab
Visage Android Hands-on Lab
 
Griffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java TechnologyGriffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java Technology
 
Android presentation
Android presentationAndroid presentation
Android presentation
 
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
 
Apache Cordova In Action
Apache Cordova In ActionApache Cordova In Action
Apache Cordova In Action
 
Building Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsBuilding Cross-Platform Mobile Apps
Building Cross-Platform Mobile Apps
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
Visage Android Hands-on Lab (OSCON)
Visage Android Hands-on Lab (OSCON)Visage Android Hands-on Lab (OSCON)
Visage Android Hands-on Lab (OSCON)
 
GUI design using JAVAFX.ppt
GUI design using JAVAFX.pptGUI design using JAVAFX.ppt
GUI design using JAVAFX.ppt
 
Lecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxLecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptx
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
Spring boot
Spring bootSpring boot
Spring boot
 
intoduction to Grails Framework
intoduction to Grails Frameworkintoduction to Grails Framework
intoduction to Grails Framework
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
 
From React to React Native - Things I wish I knew when I started
From React to React Native - Things I wish I knew when I startedFrom React to React Native - Things I wish I knew when I started
From React to React Native - Things I wish I knew when I started
 
Lezione 03 Introduzione a react
Lezione 03   Introduzione a reactLezione 03   Introduzione a react
Lezione 03 Introduzione a react
 
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
 
Installing eclipse & sdk
Installing eclipse & sdkInstalling eclipse & sdk
Installing eclipse & sdk
 
Top Ten Tips for HTML5/Mobile Web Development
Top Ten Tips for HTML5/Mobile Web DevelopmentTop Ten Tips for HTML5/Mobile Web Development
Top Ten Tips for HTML5/Mobile Web Development
 

More from eleksdev

Communication in android
Communication in androidCommunication in android
Communication in android
eleksdev
 
Hello android world
Hello android worldHello android world
Hello android world
eleksdev
 
Angular. presentation
Angular. presentationAngular. presentation
Angular. presentation
eleksdev
 
Android location and sensors API
Android location and sensors APIAndroid location and sensors API
Android location and sensors API
eleksdev
 
Frontend basics
Frontend basicsFrontend basics
Frontend basics
eleksdev
 
Advanced styles
Advanced stylesAdvanced styles
Advanced styles
eleksdev
 
Css animation, html5 api
Css animation, html5 apiCss animation, html5 api
Css animation, html5 api
eleksdev
 
Improving rpc bkp
Improving rpc bkpImproving rpc bkp
Improving rpc bkp
eleksdev
 
G rpc lection1_theory_bkp2
G rpc lection1_theory_bkp2G rpc lection1_theory_bkp2
G rpc lection1_theory_bkp2
eleksdev
 
G rpc lection1
G rpc lection1G rpc lection1
G rpc lection1
eleksdev
 
Windows service
Windows serviceWindows service
Windows service
eleksdev
 
Rpc
RpcRpc
DAL
DALDAL
Aspnet core
Aspnet coreAspnet core
Aspnet core
eleksdev
 
Web service lecture
Web service lectureWeb service lecture
Web service lecture
eleksdev
 
SDLC. QA Role
SDLC. QA RoleSDLC. QA Role
SDLC. QA Role
eleksdev
 
SDLC. UX Role
SDLC. UX RoleSDLC. UX Role
SDLC. UX Role
eleksdev
 
SDLC. PM Role
SDLC. PM RoleSDLC. PM Role
SDLC. PM Role
eleksdev
 
SDLC. BA Role
SDLC. BA RoleSDLC. BA Role
SDLC. BA Role
eleksdev
 
Version control
Version controlVersion control
Version control
eleksdev
 

More from eleksdev (20)

Communication in android
Communication in androidCommunication in android
Communication in android
 
Hello android world
Hello android worldHello android world
Hello android world
 
Angular. presentation
Angular. presentationAngular. presentation
Angular. presentation
 
Android location and sensors API
Android location and sensors APIAndroid location and sensors API
Android location and sensors API
 
Frontend basics
Frontend basicsFrontend basics
Frontend basics
 
Advanced styles
Advanced stylesAdvanced styles
Advanced styles
 
Css animation, html5 api
Css animation, html5 apiCss animation, html5 api
Css animation, html5 api
 
Improving rpc bkp
Improving rpc bkpImproving rpc bkp
Improving rpc bkp
 
G rpc lection1_theory_bkp2
G rpc lection1_theory_bkp2G rpc lection1_theory_bkp2
G rpc lection1_theory_bkp2
 
G rpc lection1
G rpc lection1G rpc lection1
G rpc lection1
 
Windows service
Windows serviceWindows service
Windows service
 
Rpc
RpcRpc
Rpc
 
DAL
DALDAL
DAL
 
Aspnet core
Aspnet coreAspnet core
Aspnet core
 
Web service lecture
Web service lectureWeb service lecture
Web service lecture
 
SDLC. QA Role
SDLC. QA RoleSDLC. QA Role
SDLC. QA Role
 
SDLC. UX Role
SDLC. UX RoleSDLC. UX Role
SDLC. UX Role
 
SDLC. PM Role
SDLC. PM RoleSDLC. PM Role
SDLC. PM Role
 
SDLC. BA Role
SDLC. BA RoleSDLC. BA Role
SDLC. BA Role
 
Version control
Version controlVersion control
Version control
 

Recently uploaded

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 

Recently uploaded (20)

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 

Lecture android best practices

  • 1. Android Development Best Practices. Android Wear by Yuriy Voznyak, Software Engineer eleks.com You can view the presentation on http://eleksdev.blogspot.com 1
  • 2. Android Wear OS for SmartWatches and wearable devices 2
  • 3. How to pair with? ● Install the Android Wear app ● Tap “Pair with a new watch” ● Tap “Enable Notifications” Some Wear devices can be paired with iOS 3
  • 4. What systems have in common? Android Wear and Android have common API. Except: ● No WebView in Wear; ● No direct internet connection: use Data Layer API instead; ● No print subsystem; ● No cloud backup subsystem; ● No application widgets (e.g. on Launchers); ● No interaction with USB devices. 4
  • 5. How to Show Notifications Do nothing :) all Push Notifications appear on Wear. Or customize notifications with Wear extensions: 5 ● User can interact with Wear notifications via Pending Intent; ● Notifications on Wear can be customized; ● Show only wearable notification, not on handheld; ● Set custom backgrounds.
  • 6. Distributing Wear apps When publishing to users, you must package a wearable app inside of a handheld app, because users cannot browse and install apps directly on the wearable. If packaged properly, when users download the handheld app, the system automatically pushes the wearable app to the paired wearable. While developing, installing apps with adb install or Android Studio directly to the wearable is required. 6
  • 7. Defining Layouts Specify Different Layouts for Square and Round Screens <android.support.wearable.view.WatchViewStub xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/watch_view_stub" android:layout_width="match_parent" android:layout_height="match_parent" app:rectLayout="@layout/rect_activity_wear" app:roundLayout="@layout/round_activity_wear"> </android.support.wearable.view.WatchViewStub> 7
  • 8. Accessing layout views The layouts that you specify for square or round screens are not inflated until WatchViewStub detects the shape of the screen, so your app cannot access their views immediately. To access these views, set a listener in your activity to be notified when the shape-specific layout has been inflated: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wear); WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(WatchViewStub stub) { TextView tv = (TextView) stub.findViewById(R.id.text); // Now you can access views ... } }); } 8
  • 9. Also You Can ● Design new Watch Faces; ● Work with built-in speakers into Wearables; ● Debug over Bluetooth; ● Send and collect data via Sync mechanism; ● … And much much more. 9
  • 10. Best Practices: Useful Libraries ● Gson; ● EventBus; ● ButterKnife ● Dagger 2 ● Glide ● DBFlow 10
  • 11. GSON Gson is a Java library used for serializing and deserializing Java objects from and into JSON. A task you will frequently need to do if you communicate with APIs. JSON is recommended to use because it’s lightweight and much simpler than XML. // Serialize String userJSON = new Gson().toJson(user); // Deserialize User user = new Gson().fromJson(userJSON, User.class); Gson works great with Retrofit as serializer/deserializer. See more on https://github.com/google/gson 11
  • 12. EventBus EventBus is a library that simplifies communication between different parts of your application. For example, sending something from an Activity to a running Service, or easy interaction between fragments. EventBus is an Android optimized publish/subscribe event bus. A typical use case for Android apps is gluing Activities, Fragments, and background threads together. Conventional wiring of those elements often introduces complex and error-prone dependencies and life cycle issues. With EventBus propagating listeners through all participants (e.g. background service -> activity -> multiple fragments or helper classes) becomes deprecated. EventBus decouples event senders and receivers and thus simplifies communication between app components. Less code, better quality. And you don't need to implement a single interface! 12
  • 13. EventBus Example public class HomeActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EventBus.getDefault().register(this); // register EventBus } @Override protected void onDestroy() { super.onDestroy(); EventBus.getDefault().unregister(this); // unregister EventBus } public void onEventMainThread(NetworkStateChanged event) { if (!event.isInternetConnected()) { Toast.makeText(this, "No Internet connection!", Toast.LENGTH_SHORT).show(); } } } public class NetworkStateChanged {} EventBus.getDefault().post(new NetworkStateChanged()); See more on http://greenrobot.org/eventbus/ 13
  • 14. Butterknife A library for binding Android views to fields and methods (for instance, binding a view OnClick to a method). Annotate fields with @Bind and a view ID for Butter Knife to find and automatically cast the corresponding view in your layout. class ExampleActivity extends Activity { @BindView(R.id.title) TextView title; @BindView(R.id.subtitle) TextView subtitle; @BindView(R.id.footer) TextView footer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_activity); ButterKnife.bind(this); // TODO Use fields... } } See more on http://jakewharton.github.io/butterknife/ 14
  • 15. Dagger 2 15 Dagger is a fully static, compile-time dependency injection framework for both Java and Android. It is an adaptation of an earlier version created by Square and now maintained by Google. Dagger creates instances of your classes and satisfies their dependencies. It relies on javax.inject.Inject annotation to identify which constructors or fields should be treated as dependencies. Dagger 2 is the successor of the famous Dagger dependency injection library. One of the major improvements is using zero reflection in generated injection code, which makes debugging a lot easier. Dagger 2 is the first to implement the full stack with generated code. The guiding principle is to generate code that mimics the code that a user might have hand-written to ensure that dependency injection is as simple, traceable and performant as it can be.
  • 16. Dagger Code Example class Thermosiphon implements Pump { private final Heater heater; @Inject Thermosiphon(Heater heater) { this.heater = heater; } ... } class CoffeeMaker { @Inject Heater heater; @Inject Pump pump; ... } 16 Also allows to resolve dependencies; Build the dependencies Graph; Resolve constructors as Singletons; Lazy Injections; Compile-time validation and much much more. Read more on http://google.github.io/dagger/
  • 17. Glide Glide is the library to use for loading images. Current alternatives are Universal Image Loader and Picasso. Glide is recommended by Google. Here's a simple example how you can use Glide to load an image from a URL into ImageView: ImageView imageView = (ImageView) findViewById(R.id.my_image_view); Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView); See more on https://github.com/bumptech/glide/wiki 17
  • 18. DBFlow The Fastest Android ORM Database Library DBFlow uses Annotation Processing functionality to generate all sorts of classes and interactions with the database at compile time. This enables the library to run at native speed and becomes as fast as writing the code yourself. Also, generating code is transparent–we can see the code that the app executes and catch errors at compile time. Reflection is difficult to debug, since we will only catch errors at runtime. List devices = new Select().from(DeviceObject.class) .where( Condition.column(DeviceObject$Table.NAME).is("Samsung-Galaxy-S5"), Condition.column(DeviceObject$Table.CARRIER).is("T-Mobile")).queryList(); Delete.table(DeviceObject.class); See more on https://github.com/Raizlabs/DBFlow 18
  • 19. It is only small amount Think about using libraries! 19
  • 20. Gradle ● Build different flavours or variants of your app ● Make simple script-like tasks ● Manage and download dependencies ● Customize keystores ● And more 20
  • 21. Maven Dependencies for Gradle The main reason is not to keep the library locally as Jar or something else apply plugin: 'com.android.application' repositories { mavenCentral() } dependencies { compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' testCompile group: 'junit', name: 'junit', version: '4.+' } Or dependencies { compile 'org.hibernate:hibernate-core:3.6.7.Final' } 21
  • 22. IDE Use Android Studio Eclipse is deprecated since 2015 22
  • 23. Components and UI ● Avoid using nested layouts; Avoid deep hierarchy for views ● Use styles instead of views spot customization; ● Don`t put much code to Activities or Fragments; ● Dont`use Intents for in-application communication. Use RxJava or EventBus if possible; ● Don`t rely on Android System-level intents. 23
  • 24. ProGuard ProGuard is a tool for code obfuscation, shrinking and optimization ● Use it; ● Verify Release builds for ProGuard rules; ● Keep mapping.txt for every release. 24
  • 25. Naming Convention Naming Convention Must Be! Bad naming convention is better than no convention 25
  • 26. Useful Links ● https://github.com/futurice/android-best-practices ● https://developer.android.com/guide/practices/index.html ● https://developer.android.com/training/best-performance.html ● https://developer.android.com/training/best-ui.html ● http://www.innofied.com/13-android-development-best-practices/ ● https://github.com/ribot/android- guidelines/blob/master/project_and_code_guidelines.md ● https://google.com 26
  • 27. It`s Questions Time Find us at eleks.com Have a question? Write to eleksinfo@eleks.com 27
  • 28. Inspired by Technology. Driven by Value. Find us at eleks.com Have a question? Write to eleksinfo@eleks.com 28