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

Loeng 8

Loeng 8

Indrek Kõue

May 28, 2015
Tweet

More Decks by Indrek Kõue

Other Decks in Education

Transcript

  1. CLEAN CODE Universal guideline Good code: • Small methods and

    classes • Variables, methods and class names with meaningful names • Comment only when (self documenting) code itself fails to express what is done • Document why is something done, now what • Avoid any duplication • Consistent formatting and style
  2. JAVA NAMING CONVENTIONS Classes: nouns, ex. BalanceSheet.class Methods: verbs, ex.

    calculateWage() Variables: lowerCamelCase ex. int totalPayroll = 10000; Note: Don’t use m prefix for local variables ex. mTotalPlayroll Constants: uppercase characters separated by underscores, ex. final int MONTHS_IN_A_YEAR = 12;
  3. BY VALUE AND BY REFERENCE Pass by value: A copy

    is created and passed to the method. All primitive data types are passed by value (byte, short, int, long, float, double, char, boolean) Pass by reference: When passing object, you're passing an object reference. Note: Each primitive has also a wrapper object, ex. int -> Integer which acts as reference type Note2: String object is specially handled: object which is not changeable
  4. BY VALUE AND BY REFERENCE void doSomething(){ int index =

    3; addTwo(index); //index = index + 2 System.out.println(index); }
  5. BY VALUE AND BY REFERENCE Person mary = new Person("Mary",

    32); Person jack; jack = mary; jack.set("Jack", 22); System.out.println(mary);
  6. POLYMORPHISM Ability of an object to take many forms. Parent

    reference is used to refer to a child. That’s why this is correct: Context context = getActivity(); Example: class Cat extends Animal Cat cuteKitten = new Cat(); Animal referenceToAnAnimal = cuteKitten;
  7. NATIVE HTML ALTERNATIVES Cross platform HTML applications. Promise: write once,

    run everywhere Reality (most cases): write once, suck everywhere Downsides: • Slow • May be locked to a certain closed source framework • UI looks the same on every platform • Another layer of complexity (black box)
  8. FUTURE OF ANDROID Android apps on desktop App Runtime for

    Chrome (Beta) to run Android apps on Windows/OS X/Linux (Google Chrome plugin) Android wearable Glasses, watches, what next? Android auto Car manufacturers use Android as multimedia platform. Manufactures on board: Audi, Ford, Honda, Mazda, Nissan, Volkswagen, Volvo etc.
  9. FUTURE OF ANDROID Internet of things Android based OS is

    used in internet of things devices (connected devices with limited resources ex. door locks, lamps etc.) Android apps porting to Windows Port apps to windows 10 (includes Windows Phone) Minimal changes needed.
  10. GOOGLE PLAY PUBLISHING No human review process Do NOT: •

    Infringe copyright • Keyword spam If you do: • Auto banned by robots • Banned for life • No way to get feedback why where you banned: Google support is nonexistent
  11. GOOGLE PLAY PUBLISHING Potential streams of income: • advertisements (banners,

    full screen) • application sales • in app billing • or all previous Since 2015 you can sell apps from Estonia
  12. WORKFLOW AT APPLAUD 1 developer per project = easy to

    manage 1+ developers per project = complicated. Workflow has to structured and rules needed to avoid (code)conflicts and work efficiently How we develop: 1. Each fix or feature is developed on feature branch 2. If completed, pull request and submitted for review (by other developer in the project) 3. If code review passed, merge into main branch 4. Make a release and send to testing 5. If tests passed = Job done
  13. PRACTICE AT APPLAUD Applaud takes trainees for summer/fall Application date:

    12 jun Positions: software engineer in test or developer About us: ~10 employees, office in Telliskivi loomelinnak Very interested in people who have completed this subject Contact: [email protected]
  14. TOP 5 EVERYDAY PROBLEMS Problem: Transfer complex objects between Activities

    Easy with primitive data types but what if object with 40 properties? Setting object as public static = bad practise (potential bugs, hard to debug) Solution: Make object Parceable • CustomObject implements Parcelable • intent.putExtra(KEY, myCustomObject) Note: Making object Serializable is not recommended due to performance penalty
  15. TOP 5 EVERYDAY PROBLEMS Problem: Unique device ID • TelephonyManager.getDeviceId()

    returns null on tablets and needs an extra permission • Write UUID to internal storage - could be wiped by user Solution: String uniqueId = Secure.getString(getContext(). getContentResolver(), Secure.ANDROID_ID); Notes: • Survives app uninstalls and installs • Multiple users each have unique id • Does not survive device reset
  16. TOP 5 EVERYDAY PROBLEMS Problem: On device rotate all states

    are lost Solution: Set android:configChanges="orientation|screenSize" in Manifest Note: Handling the configuration change yourself will make it harder to use alternative resources
  17. TOP 5 EVERYDAY PROBLEMS Problem: How to emulate situation of

    app being on background for a long time? Solution: Settings >> Developer Options (needs to be enabled) >> Don’t keep activities Tells the system to destroy an activity as soon as it is stopped (as if Android had to reclaim memory). Note: If objects are set public static they won’t be destroyed
  18. TOP 5 EVERYDAY PROBLEMS Problem: TextView setText(integer) crashes: why? If

    you use setText(123), the method TextView.setText(int resourceId) is called not TextView.setText(CharSequence text) Solution: setText(123+””) or setText(String.valueOf(123)) or setText(Integer.toString(123))
  19. EVERYTHING WE HAVE TALKED ABOUT THIS COURSE Activity Single screen

    Activity lifecycle onCreate - create UI here onResume - activity is active onPause - activity is partially covered onStop - activity in background Backstack History of activities
  20. EVERYTHING WE HAVE TALKED ABOUT THIS COURSE Context Object needed

    for accessing resources (screen drawing, writing to internal storage etc.) Intent Something going to be done (mostly Activity start). May include data for transfer. Intent-Filter Captures system wide implicit intents
  21. EVERYTHING WE HAVE TALKED ABOUT THIS COURSE Fragments Part of

    user interface. Many similar lifecycle callbacks as activity. Can be combined, added, removed etc. in UI Layout • Reference resources by ID not by file path • Can use OS resources by prefixing with “android” Alternative resources • Automatically built in system for configuration based resources • Divide resources into different folders in res folder and system automatically applies correct one
  22. EVERYTHING WE HAVE TALKED ABOUT THIS COURSE Broadcast • Event

    notification that something happened • Can be global or local Broadcast Receiver • Receives broadcasts (system wide or local) • Allows to implement custom logic when broadcast is received
  23. EVERYTHING WE HAVE TALKED ABOUT THIS COURSE RESTful services •

    Most android applications are clients connected to REST API • JSON = human readable data format • REST service = HTTP + data type
  24. TODAY I TALKED ABOUT Clean code Java naming conventions By

    value and by reference Polymorphism Native HTML alternatives Future of Android Google play publishing Workflow at Applaud Practice at Applaud Top everyday problems Rehearsal of everything
  25. ?