Slide 1

Slide 1 text

Fundamentals of creating Android mobile apps Scott Alexander-Bown [email protected] @scottyab

Slide 2

Slide 2 text

WHO THE HECK IS THIS GUY? ➤ Senior Android Developer @ Help Scout ➤ Remote, in Bristol ➤ Google Developer Expert for Android ➤ Founder/Organiser SWMobile Meetup ➤ http://swmobile.org ➤ Co-Author Android Security Cookbook ➤ Follow on Twitter @scottyab @scottyab

Slide 3

Slide 3 text

@scottyab TOO MUCH CONTENT!

Slide 4

Slide 4 text

AT A GLANCE ➤Intro ➤Fundamentals ➤Android, toolkit and ecosystem ➤Android App Components ➤Development Tips ➤Don’t reinvent the wheel (use open source code) ➤What next?

Slide 5

Slide 5 text

“ “Ok, Google… How do I create my first Android app” https://developer.android.com/training/basics/firstapp/

Slide 6

Slide 6 text

MOBILE APPS != WEB SITE ➤ Screen size ➤ User context - maps/GPS/bluetooth/camera/accelerometer ➤ Platform integration ➤ Interaction model - glanciblity not sit down focus ➤ Intuitive (focused actions) ➤ Work offline ➤ Permissions - well defined

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

ANDROID, TOOLKIT AND ECOSYSTEM

Slide 9

Slide 9 text

What is Android?

Slide 10

Slide 10 text

https://developer.android.com @scottyab

Slide 11

Slide 11 text

@scottyab

Slide 12

Slide 12 text

EMULATOR ➤ Don’t need an actual device ➤ although testing on one is recommended ➤ GPS/Cellular/Battery/Virtual sensors ➤ Screen recording/Screen shot ➤ Snap shots

Slide 13

Slide 13 text

.APK AND DISTRIBUTION ➤ Android apps are packaged as .apk or .aab ➤ Signed with signing key ➤ Upload to the Play Store • $25 one off registration fee • Screen shots • Unique App Id developer.android.com/distribute/best-practices/launch/launch-checklist.html

Slide 14

Slide 14 text

ANDROID COMPONENTS The core concepts and classes you’ll use on day one

Slide 15

Slide 15 text

@scottyab @scottyab

Slide 16

Slide 16 text

ACTIVITY ➤ AKA a Screen ➤ has distinct lifecycle ➤ onCreate() ➤ onStart() ➤ onResume() ➤ onPause() ➤ onStop() ➤ onDestory() https://play.google.com/store/apps/details?id=name.peterscully.learning.activitylifecycle @scottyab @scottyab

Slide 17

Slide 17 text

RESOURCES AND LAYOUTS ➤ Layouts • Xml ➤ Values • Strings • Styles ➤ Drawables

Slide 18

Slide 18 text

DESIGN XML

Slide 19

Slide 19 text

INTENTS (USE FOR OPENING NEW ACTIVITIES) ➤ Action ➤ Extra ➤ Primitives ➤ Parcelables public void sendMessage(String message) {
 Intent intent = new Intent(this, DisplayMessageActivity.class);
 intent.putExtra(EXTRA_MESSAGE, message);
 startActivity(intent);
 } @scottyab @scottyab

Slide 20

Slide 20 text

@Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_display_message);
 
 Intent intent = getIntent();
 String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
 
 TextView messageText = (TextView)findViewById(R.id.messageText);
 messageText.setText(message);
 }

Slide 21

Slide 21 text

SERVICES ➤ Background operations ➤ Lifecycle ➤ Service ➤ Bind ➤ IntentService ➤ Work thread ➤ Start with Intent @scottyab @scottyab

Slide 22

Slide 22 text

ANDROID MANIFEST.XML @scottyab

Slide 23

Slide 23 text

DEVELOPMENT TIPS

Slide 24

Slide 24 text

Plan on paper!

Slide 25

Slide 25 text

GET OFF THE UI THREAD - ASYNCTASK ➤ Yes, there are better ways (Kotlin Coroutines, RX Java, Threadpool executor, …) ➤ But for getting started check out AsyncTask ➤ Set up ➤ onPreExecute() ➤ Do this work in the background ➤ doInBackground(arguments) ➤ Here’s the result on the main thread for you ➤ onPostExecute(result) @scottyab https://developer.android.com/reference/android/os/AsyncTask

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

SAVING DATA ➤ Files (internal and external storage) ➤ SQLite ➤ Use Room persistent library a wrapper on top of SQLite ➤ Shared preferences ➤ Simple to use ➤ Combine with JSON parsing to save @scottyab https://developer.android.com/guide/topics/data/data-storage.html#pref

Slide 28

Slide 28 text

MISC TIPS* ▸ Logic out of the View (i.e Activity or Fragments) ▸ Easier to test ▸ Simple architecture (MVP or MVVM) ▸ Constructor based dependancies ▸ Lock to portrait ▸ Test on real devices ▸ Min SDK 23 @scottyab * For your first app

Slide 29

Slide 29 text

AVOID* ▸ RX Java ▸ Dagger ▸ Child Fragments ▸ Cross platform ▸ Bleeding edge! ▸ Jetpack Compose @scottyab * For your first app

Slide 30

Slide 30 text

DON’T REINVENT THE WHEEL Dependancies & 3rd Party Libs

Slide 31

Slide 31 text

GRADLE ➤ Run from CI and IDE ➤ Easy dependancy management ➤ Build variants • types • flavours

Slide 32

Slide 32 text

INCLUDING DEPENDANCIES ➤ build.gradle @scottyab

Slide 33

Slide 33 text

ANDROID JETPACK ➤ UI components provide widgets and helpers ➤ Architecture components help you design robust, testable and maintainable apps. ➤ Backward-compatible versions of framework components. ➤ Miscellaneous utility functions. https://developer.android.com/jetpack/ @scottyab

Slide 34

Slide 34 text

CONVERT JAVA OBJECTS INTO JSON AND BACK https://github.com/google/gson API: GSON @scottyab

Slide 35

Slide 35 text

T ANDROID-ARSENAL.COM

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

WHAT NEXT?

Slide 38

Slide 38 text

VIDEO CONTENT ➤ https://www.youtube.com/user/androiddevelopers/featured ➤ https://www.udacity.com/course/android-developer-nanodegree-by-google--nd801 ➤ @scottyab

Slide 39

Slide 39 text

SAMPLE APPS ▸ github.com/android/sunflower ▸ github.com/google/iosched ▸ github.com/googlesamples/android-topeka ▸ github.com/nickbutcher/plaid ▸ github.com/chrisbanes/philm ▸ github.com/JakeWharton/u2020 ▸ github.com/googlesamples @scottyab

Slide 40

Slide 40 text

https://kotlinlang.org

Slide 41

Slide 41 text

@scottyab TOO MUCH CONTENT???

Slide 42

Slide 42 text

THANKS swmobile.org @scottyab [email protected] QUESTIONS?

Slide 43

Slide 43 text

SWMOBILE MEETUP @scottyab