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

Face off: Android vs iOS

seviu
April 25, 2016

Face off: Android vs iOS

A talk Vikram and me gave for AppBuilders Switzerland 2016
State of Android and iOS in 2016. What are the similarities? What are the differences?

seviu

April 25, 2016
Tweet

Transcript

  1. Xcode Some features: • Swift and Objective-C • Powerful refactoring

    tools • Interface Builder • Storyboards • 2D & 3D Scenes • Particle designer! • Playgrounds! • etc.
  2. Xcode Some features: • Swift and Objective-C • Powerful refactoring

    tools • Interface Builder • Storyboards • 2D & 3D Scenes • Particle designer! • Playgrounds! • etc.
  3. Android Studio: IntelliJ 15 Some features: • Best Java IDE

    • Powerful refactoring tools • Code analysis • Integration with Google services ◦ URL and App Indexing support ◦ App Engine integration ◦ Google play services • Testing • Powerful Layout Editor and Translations Editor
  4. Android Studio: Android Emulator No more 10 minutes boot time

    with Intel® Hardware Accelerated Execution Manager
  5. Android Studio 2.0: Instant Run Pushes changes to methods and

    existing app resources without building a new APK Gradle version 2.0.0 or higher Targeting devices running Android 4.0 Still a bit flaky (it does not play well data binding)
  6. Simulator: iOS, watchOS, tvOS Some features: • Much faster than

    Android Emulator • It’s a Mac OS X i386 app • Debugging tools: ◦ Graphics rendering ◦ Location ◦ Localizations ◦ Accessibility ◦ iCloud • Still missing real multitouch (and force touch)!
  7. Android Studio: Translations Editor View and update all your string

    resources in one convenient place. • “Order a translation” • Refactor!
  8. Localizing Apps Hello world Hallo Welt Hola mundo नम ते

    दु नया Bonjour monde • Translating iOS apps sucks eggs • Obscure command-line tools and formats • The lazy man’s approach: Google Sheets! • Here’s my template: https://goo.gl/k4A3sa • Demo!
  9. Even more laziness: Localizing Apps prefix func ~ (key: String)

    -> String { return NSLocalizedString(key, comment: "No Comment") } print(~"hello") > Hola
  10. Gradle Natively supported by Android Studio Multiple dependencies support It

    is also a build system, not just a dependency manager (like cocoapods): • Top level build file + Module level build files
  11. Gradle tips Check for the latest version: • http://gradleplease.appspot.com/ dataBinding:

    enabled true dexOptions: javaMaxHeapSize 2048 For the brave: useJack true Testing: testCompile (src/test) and androidTestCompile (src/androidTest))
  12. Third Party Libraries & Dependencies • Cocoapods • Carthage •

    Swift Package Manager target 'MyBeautifulApp' do pod 'AFNetworking', '~> 3.0' end
  13. Getting ready to submit an app: Proguard Obfuscate all ze

    things! • minifyEnabled true Shrink resources! • shrinkResources true • Important to remove unused library code Beware: -keep public class MySpecialClass Backup output files (specially mapping.txt)
  14. Getting ready to submit an app: Signing Create a Keystore

    and a private key and off you go gradle assembleRelease Or just use Android Studio: Build > Generate Signed APK Submitting an Android app in the Google Play store is just super easy release { storeFile file("_market/android_market.keystore") storePassword "android" keyAlias "androiddebugkey" keyPassword "android" }
  15. Equivalent to iTunes Connect but... • No App review process

    (almost never, right?) • Always do staging releases • Use Beta and Alpha distribution channels • It is possible to make experiments • And much more... Google Play Developer Console
  16. Getting to the App Store: iTunes Connect • Apple review

    process ◦ Quality filter ◦ Expedited review • TestFlight ◦ Internal ◦ External
  17. Android Studio: Cloud Test Lab Temporarily available to use at

    no charge Run Instrumentation tests or Robo tests (if you do not have tests)
  18. Apple Device Cloud • Thousands of devices available remotely for

    testing! • Just kidding! • Seriously, what fragmentation? • Developers can get away with 3-4 hardware devices • iOS update propagation is phenomenal
  19. Google Play Services Over 90% Adoption rate Google Play Services:

    more important than Android • It is not included in the Android Open-Source Project (AOSP) • Device manufacturers: Why u not update? No need to multidex: compile 'com.google.android.gms:play-services-appindexing:8.4.0' compile 'com.google.android.gms:play-services-analytics:8.4.0' compile 'com.google.android.gms:play-services-gcm:8.4.0' compile 'com.google.android.gms:play-services-maps:8.4.0'
  20. Apple’s Strategy No need to have a separate library of

    services - It is enough to support the latest 2 major versions of iOS - Adoption rate is so high that this covers 95% of iOS users And there are ways to check which version you run: guard #available(iOS 9, *) else { return }
  21. Intents Intents are messaging objects to request action from other

    app components You can start an activity, a service or send a broadcast
  22. iOS URL Schemes • Simple way to launch another app

    • Apps declare custom URL schemes, e.g. localch:// • Apps can check if the system can open a URL* • Parameters are passed in the URL: localch://tel/search?what=vikram
  23. iOS Extensions • Action • Audio Unit • Content Blocker

    • Custom Keyboard • Document Provider • Photo Editing • Share • Today widget
  24. iOS Today Extensions Similar to Android widgets. • Get a

    quick update • Perform a quick task in the Today view of Notification Center A use case: what are the next departures around me?
  25. Widgets Remote views that run on other App (typically home

    or lock screen) • This is because they run on the original App process Very limited with a small set of UI elements It is basically a broadcast receiver… … but are we limited to widgets on Android? Not really
  26. Android programming language Official language: Java…. Everybody knows Java these

    days. • robust • verbose • ...boring But there are alternatives! • Scala • … and more
  27. Kotlin Small runtime file size: 823Kb (vs 8Mb of Scala)

    It is out of beta. Current version 1.0.1 It runs on the Java Virtual Machine (it also can be compiled to JavaScript) fun main(args : Array<String>) { val scope = "App Builders" println("Hello, $scope!") }
  28. Kotlin Strong support for Android It is possible to convert

    Java code to Kotlin directly from Android Studio Support for Higher-Order Functions and Lambdas import kotlinx.android.synthetic.main.activity_main.* public class MyActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) textView.setText("Hello, world!") // No need for findView(R.id.textView) } }
  29. Swift What? Swift on Android? Android support was merged not

    long time ago • Requires the NDK • https://github.com/apple/swift/pull/1442 https://github.com/SwiftAndroid/
  30. Swift Some features: • Optionals, unwrapping • Type-inference • Higher

    level functions • Protocol-Oriented • Etc. etc. • Open Source!
  31. Vulkan Low level API brought by Khronos (OpenGL) Successor of

    Mantle (AMD) who donated it to the Khronos group Supported by everybody except Apple (Metal) Supported in Android N
  32. Metal • Lower level alternative to OpenGL ES • Optimized

    for iPhone and iPad hardware • Up to 10x faster than drawing with OpenGL • "Bare metal" API with less driver overhead and more direct control over the GPU on the A7 chip
  33. App Indexing Mapping URLs to Activities Supports iOS and Android

    Google literally crawls your app and associates it to search results Used at local.ch: it increased usage by 5% Used on iOS with deep linking… Still trying to figure out if it works
  34. iOS Continuity: Deep Linking • App bundle specifies associated domains

    (entitlements) • Website serves apple-app-site-association file: "applinks": { "apps": [], "details": { "HGPZCPK6NY.ch.local.search.launcher": { "paths": [ "*" ]
  35. iOS Continuity: Handoff (and Spotlight) /// Updates the given user

    activity or creates one for this entry func updateUserActivity(activity: NSUserActivity?, ... { // Handoff support (since iOS 8.0) activity.title = title activity.userInfo = [kDetailActivityEntryIdKey: entryId] activity.webpageURL = myWebpageURL // Enable Handoff, Spotlight and public indexing activity.eligibleForHandoff = true activity.eligibleForSearch = true activity.eligibleForPublicIndexing = true
  36. Runtime Permissions … Android M … Lower versions: Manifest. Google

    Play will ask for critical permissions. No way to know if you already asked The activity gets the callback Lots of conditional code It is still better and probably cleaner than on iOS Confusing at the beginning… Maps anyone?
  37. Permissions on iOS • Ask, but only when the time

    is right • Location, Contacts, Notifications, Photos, Camera, Microphone, Bluetooth, HealthKit… • Explain why your app needs it • Allow user to change their mind
  38. Data Binding Say goodbye to findViewById Support library down to

    Android 2.1 (Api v7) Similar to ButterKnife or what Xcode does in Interface Builder (outlets) But it lets you run code with an Expression Language similar to Java You can have observable objects, fields and collections Support for basic data types and collections
  39. Android N - Doze Doze is the new Doze It

    kicks in intervals called maintenance windows (screen off) It is doze as on M but better
  40. Android N: Multi-Window Support Two apps on screen at the

    same time The other app will be paused and not stopped (activity lifecycle) And a new Intent flag: Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT Picture-in-Picture for Android TV, to run in miniature form on top of everything else <activity android:name=".AppBuildersDemo" android:resizeableActivity="true"> <layout android:minimalSize="500dp"/>
  41. Android N: Notifications Total visual redesign plus new functionalities Inspired

    from Android Wear • Direct Reply • Grouping notifications: ◦ Enabled by default on all apps. ◦ Summary customizable. Compatible with older versions of Android thanks to NotificationCompat
  42. Android N: Direct Boot Start your app before a user

    has unlocked an encrypted device Imagine your phone restarts while you are asleep Good for alarm clock and for incoming calls <receiver android:name=".SecureBootReceiver" android:directBootAware="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver>
  43. Android N: Scoped directory access Access directories like Photos without

    asking for READ_EXTERNAL_STORAGE ..or accessing a Directory on Removable Media • Adding a BroadcastReceiver that listens for the MEDIA_MOUNTED notification StorageManager sm = (StorageManager)getSystemService(Context. STORAGE_SERVICE); StorageVolume sv = sm.getPrimaryStorageVolume(); Intent intent = sv.createAccessIntent(Environment.DIRECTORY_PICTURES); startActivityForResult(intent, request_code);
  44. iOS Sandboxing iOS is very limited when letting apps work

    together Sandboxing prevents accessing the filesystem • Only access to Photos can be enabled • App Groups for sharing files between apps
  45. Android fun SensorManager: • public static final float GRAVITY_DEATH_STAR_I of

    the first Death Star in Empire units (m/s^2) 3.5303614E-7 public static final float GRAVITY_THE_ISLAND of the island (Lost): 4.815162 Log: public static int wtf (String tag, Throwable tr) What a terrible failure
  46. Android fun ActivityManager: public static boolean isUserAMonkey () Returns "true"

    if the user interface is currently being messed with by a monkey. AdapterViewFlipper: public void fyiWillBeAdvancedByHostKThx () Called by an AppWidgetHost to indicate that it will be automatically advancing the views of this AdapterViewFlipper by calling advance() at some point in the future. UserManager: public boolean isUserAGoat () Used to determine whether the user making this call is subject to teleportations. As of LOLLIPOP, this method can now automatically identify goats using advanced goat recognition technology.
  47. Android fun Handler: public final boolean runWithScissors(final Runnable r, long

    timeout) Public but not in the official API. It runs the specified task synchronously. However, this problem is often a symptom of bad design. Consider improving the design (if possible) before resorting to this method. Boring classes BoringLayout is a very simple Layout implementation for text that fits on a single line and is all left-to-right characters. You will probably never want to make one of these yourself. BoringSSL is the SSL library in Chrome/Chromium an Android (boring indeed)
  48. The Mythical Context Switch • It does exist. • But

    it can be good for you! • Become a Mobile Ninja.
  49. Thank You. Vikram Kriplaney @krips - https://github.com/markiv Sebastián Vieira @seviu

    - https://github.com/seviu Check out this presentation (including bonus slides) here: https://goo.gl/IwqE3x
  50. Awesome iOS resources https://www.raywenderlich.com iOS Human Interface Guidelines (what everybody

    claims has read) http://www.cocoawithlove.com/ http://iosdevweekly.com/ And all the WWDC videos
  51. Support libraries: It is about compatibility Google’s strategy to support

    all versions of iOS (down to Android 2.3) v4 Support Library • App Components, User Interface, Accessibility, Content v7 appcompat library (ActionBar),cardview, gridlayout, mediarouter, palette, recyclerview, Preference Support v8 renderscript , V13, v14, v17 (Android TV), Annotations, Design... useLibrary 'org.apache.http.legacy'
  52. What is LLVM LLVM is a compiler technology which works

    in two steps. 1) It compiles the source code to an intermediate form. (front end) 2) Converting the virtual assembly language into machine language of the target computer. (back end)
  53. Bitcode An “intermediate” language like Bitcode is an abstract encoding

    of an app that can be used to re-compile it in different ways, given a set of instructions. Apple can simply add support for new CPUs to the “back end” on the App Store, which will show Bitcode how to compile down to new architecture.
  54. Tasker - or why Android is awesome Event based, tasker

    lets you perform certain actions • Launch a time tracking app when you are at work • Do something when you get an SMS from a certain friend • Open spotify when plugging your headphone Automate device actions the way IFTTT interacts between web services Tasker relies heavily on intents to do such things Being able to do this kind of things makes Android awesome
  55. Android and other things that you cannot do on iOS

    Like running a view on top of everything else Getting a broadcasts when the device starts up or gets a phone call Having a service that runs in the background • At the cost of draining the battery of your phone in no time… No memory leaks since it runs on a Java in a VM and there is a GC. Right?
  56. Stuff you can do on iOS but not on Android

    Storyboards Interactive Playgrounds! Low-latency audio 3D Touch, Peek and Pop Content Blockers!
  57. iOS Storyboards And how you can tie them with actions

    and properties Demo how you can set properties on the view (modify layer?) with runtime attributes Talk about how data binding has been with us since the start: Outlets connect Actions, Properties, Segues, Layout Constraints with your code Designables – complete custom views that can be
  58. What’s new on Swift 3 https://github.com/apple/swift-evolution Stable ABI and Resilience

    Bye bye this: for (i=0; i<4; i++) { } No more var as function parameters Swift now belongs to the community (feel free to add features)
  59. Android N: Multiple Locales Because there are people that speak

    more than one language Call LocaleList.getDefault() to get the full list • Show search results in multiple languages • No more annoying popups offering to translate content
  60. Android N: Project Svelte Focused on optimizing the way apps

    run in the background. It is an effort to prevent memory thrashing in response to an implicit broadcast JobScheduler will trigger jobs on ContentProvider updates: CONNECTIVITY_CHANGED will not trigger receivers declared in manifest NEW_PICTURE and NEW_VIDEO cannot longer be sent or received. No more camera freezing! But fear not: if the app is already running it will get the broadcast with context. registerReceiver
  61. Memory leaks … yes there are leaks. Mostly context leaks

    Do not keep long-lived references to a context-activity Try using the context-application • But do not use the App context for everything • Do you do not use the application context for things that have to do with UI • https://possiblemobile.com/2013/06/context/ Avoid non-static inner classes in an activity (use weak references to activities)
  62. How to avoid memory leaks Capture the heap with the

    Dalvik Debug Monitor Server Run MAT (Eclipse Memory Analizer - http://www.eclipse.org/mat/) Very tedious Use https://github.com/square/leakcanary instead
  63. We can know if data saver is active for our

    app and react according to that ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.isActiveNetworkMetered()) { // Checks user’s Data Saver settings. switch (connMgr.getRestrictBackgroundStatus()) { case RESTRICT_BACKGROUND_STATUS_ENABLED: // Background data usage is blocked for this app. Wherever possible, // the app should also use less data in the foreground. case RESTRICT_BACKGROUND_STATUS_WHITELISTED: // The app is whitelisted. Wherever possible, // the app should use less data in the foreground and background. case RESTRICT_BACKGROUND_STATUS_DISABLED: // Data Saver is disabled. Since the device is connected to a // metered network, the app should use less data wherever possible. } } Android N: Data Saver improvements