Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fundamentals of creating Android mobile apps

Fundamentals of creating Android mobile apps

Intro to developing apps on Android for students of CompSci Bristol Uni with basic Java knowledge.

* Android and our tool Kit
* Android App Components
* Development Tips
* Don’t reinvent the wheel (use open source code)
* What next?

Scott Alexander-Bown

November 08, 2019
Tweet

More Decks by Scott Alexander-Bown

Other Decks in Technology

Transcript

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

    View Slide

  2. 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

    View Slide

  3. @scottyab
    TOO MUCH CONTENT!

    View Slide

  4. 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?

    View Slide


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

    View Slide

  6. 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

    View Slide

  7. View Slide

  8. ANDROID, TOOLKIT AND ECOSYSTEM

    View Slide

  9. What is Android?

    View Slide

  10. https://developer.android.com
    @scottyab

    View Slide

  11. @scottyab

    View Slide

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

    View Slide

  13. .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

    View Slide

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

    View Slide

  15. @scottyab
    @scottyab

    View Slide

  16. 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

    View Slide

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

    View Slide

  18. DESIGN XML

    View Slide

  19. 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

    View Slide

  20. @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);

    }

    View Slide

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

    View Slide

  22. ANDROID MANIFEST.XML
    @scottyab

    View Slide

  23. DEVELOPMENT TIPS

    View Slide

  24. Plan on paper!

    View Slide

  25. 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

    View Slide

  26. View Slide

  27. 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

    View Slide

  28. 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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  32. INCLUDING DEPENDANCIES
    ➤ build.gradle
    @scottyab

    View Slide

  33. 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

    View Slide

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

    View Slide

  35. T
    ANDROID-ARSENAL.COM

    View Slide

  36. View Slide

  37. WHAT NEXT?

    View Slide

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

    @scottyab

    View Slide

  39. 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

    View Slide

  40. https://kotlinlang.org

    View Slide

  41. @scottyab
    TOO MUCH CONTENT???

    View Slide

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

    View Slide

  43. SWMOBILE MEETUP @scottyab

    View Slide