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

Android Programming Introduction

Avatar for Bruce Tsai Bruce Tsai
February 02, 2015

Android Programming Introduction

An introduction to Android programming with fundamental concepts, including activity life cycle and fragment. The slides are based on book "The Big Nerd Ranch Guide" and some images are from site of Android Developer.

Avatar for Bruce Tsai

Bruce Tsai

February 02, 2015
Tweet

More Decks by Bruce Tsai

Other Decks in Programming

Transcript

  1. Multitasks Task is cohesive unit that can move to “background”

    when user begins a new task or go to Home screen 5
  2. Intent Object that component uses to communicate with OS Explicit

    intent — start activities within application create Intent with Context and Class Implicit intent — start activities in another application 7
  3. Put Intent Extras (parent) Intent i = new Intent(QuizActivity.this, CheatActivity.class);!

    i.putExtra(CheatActivity.EXTRA_ANSWER_IS_ TRUE, true);! startActivity(i); 9
  4. 11

  5. Handle Result (parent) protected void onActivityResult(int requestCode, int resultCode, Intent

    data) {! ! if (data == null) return;! ! mIsCheater = ! data.getBooleanExtra(CheatActivity.EXTRA_A NSWER_SHOWN, false);! } 14
  6. Fragment Host Activity defines a spot in its layout for

    fragment’s view Activity manage lifecycle of fragment instance Hosting approaches: add to layout or add to code 17
  7. Fragment Transaction Usages of fragment in activities are add, remove,

    replace and perform other actions Each set of changes that is committed to activity is fragment transaction 19
  8. FragmentManager fm = getSupportFragmentManager();! Fragment fragment = fm.findFragmentById(R.id.fragmentContainer);! if (fragment

    == null) {! ! fragment = new CrimeFragment();! ! fm.beginTransaction()
 ! .add(R.id.fragmentContainer)
 ! .commit();! } 20
  9. SDK Versions Minimum SDK version — hard floor below which

    the OS should refuse to install the app Target SDK version — API level the app is designed to run on Build SDK version — private information between you and compiler 21