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. 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
  2. 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?
  3. “ “Ok, Google… How do I create my first Android

    app” https://developer.android.com/training/basics/firstapp/
  4. 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
  5. EMULATOR ➤ Don’t need an actual device ➤ although testing

    on one is recommended ➤ GPS/Cellular/Battery/Virtual sensors ➤ Screen recording/Screen shot ➤ Snap shots
  6. .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
  7. 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
  8. 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
  9. @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);
 }
  10. SERVICES ➤ Background operations ➤ Lifecycle ➤ Service ➤ Bind

    ➤ IntentService ➤ Work thread ➤ Start with Intent @scottyab @scottyab
  11. 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
  12. 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
  13. 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
  14. AVOID* ▸ RX Java ▸ Dagger ▸ Child Fragments ▸

    Cross platform ▸ Bleeding edge! ▸ Jetpack Compose @scottyab * For your first app
  15. GRADLE ➤ Run from CI and IDE ➤ Easy dependancy

    management ➤ Build variants • types • flavours
  16. 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
  17. 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