跳到主要內容

Android O 多了什麼新東西 ??

Background Execution Limits

1. 大部份在 AndroidMenifast 宣告的 Implicit BroadcastReceiver 不會被呼叫,但有些還是可以 work,如以下:
    • BOOT_COMPL
    • ETELOCALE_CHANGED
    • USB_DEVICE_ATTACHED
    • Explicit BroadcastReceiver 沒什麼改變,還是可正常發送。Runtime Implicit BroadcastReceiver 也沒什麼改變。
      2. Service 也有些改變,如以下: 
      • Run minimally after the app has been background (這要開發者怎麼決定哪些是一定要在背景執行的阿…)
      • App 在背景時,不能使用 startService() 跟 PendingIntent
      • Foreground service 不變,多了新 API 可以使用,NotificationManager#startServiceInForeground
      3. When you app enter cache state with no active component, weak locks be automatically released.

      4. Location
      • Background Location Limited updates, few times per hour
      • Passive Location Unchanged (這句在說啥?)
      • 有其他 app 在前景使用 Location update,你的 background location 更新的頻率會跟前景一樣 (所以重點就是要有 app 在前景要 location 的資料!)
      • Foreground Location 沒改變

      Settings.Secure.ANDROID_ID

      其實這個我看不懂他在說什麼,之前完全沒碰過…
      • pre-O:每個 app 的 ID 都一樣
      • post-O:每個 app 都會有個獨立的 ID (影片說由 Google Play Service 管嗎?)

      Account access

      • 不能用 GET_ACCOUNTS 這個 permission 了
      • 要改用 newChooseAccountIntent (AccountManager 跟 Google Play Service library 都有)

      Notification Channel

      • 大意就是提供一個統一的用法讓使用者管理 notification
      • App 設定在 Android O 的話,至少要實作一組 notification channel
      • 不是設定在 Android O 的話就不用管這個
      • 詳情請看官方介紹

      Autofill Framework

       讓使用者便於輸入使用者相關的個人資訊,減少使用者打錯的機會,並節省時間
      • Addresses
      • Credit card information
      • user name
      • password
      • 支援 custom view,但要額外實作一些 method
      • 詳情請看官方介紹

      Picture in Picture

        在 Android M 時 PIP mode 只支援 Android TV,在 Android O 所有的 device 都支援 PIP mode 了。新 API PictureInPictureArgs 可以設定 PIP mode,如畫面比例等。詳情請看官方介紹

      Multi Display Support

      Android O 有支援 multi display。假如你的 app 設定 Android O,執行在有 multi display 的 device 上時,使用者可以自由切換 activity 要在哪個 display 顯示。不過開發者在發佈 app 最好要測試過這個功能。

      Font Resources

      簡單說就是 resource 終於有 font 可以用了,如 R.font.your_font。詳情請看官方介紹


      這篇只是重點節錄上面 youtube 影片的內容,新功能還是要親自使用過後才會比較有感覺喔 (我也不知道自己哪時候會試,我到現在都還沒有 Android N 的 device…)

      參考資料

      Android O preview
      Android O Features and APIs

            留言

            這個網誌中的熱門文章

            如何把 Status Bar 變透明

                    Android 從 4.4 (KitKat, api level 19) 後才支援這個功能, 到了 5.0 (Lollipop, api level 21) 自訂性更高, 可以讓我們設定各種顏色, 當然也包含透明色。以下分別介紹如何使用這兩種版本的方法。         方法1: 利用 attribute " android:windowTranslucentStatus ", 在 style.xml 加上這個 attribute 就好。要注意的是 Android 版本要在 4.4 以上才可以用這個 attribute: <resources> <!-- Base application theme for API 19+. This theme completely replaces AppTheme from res/values/styles.xml on API 19+ devices. --> <style name="AppTheme" parent="@style/AppBaseTheme"> <!-- API 19 theme customizations can go here. --> <item name="android:windowTranslucentStatus">true</item> </style> </resources>         下面的圖分別為 4.4 跟 5.0 的手機使用這個 attribute 的結果:         因為設定了這個 attribute, 畫面會從 status bar 下方開始畫。要解決這個有兩種方法, 第一個是在 layout 畫面設定 attribute "android:fitsSystemWindows " <RelativeLayout xmlns:android="http://schemas.android.com/apk/res

            探討 LayoutInflater 的 inflate method

                    在 Android 程式裡要動態新增 View,最直接的方法就是使用 LayoutInflater 提供的 inflate method。比較常用的有以下兩個 method: inflate(int resource, ViewGroup root) inflate(int resource, ViewGroup root, boolean attachToRoot)         第一個參數 resource,就是 layout xml file,如 R.layout.your_file。第二個參數 root,指的是這個 inflate 的 view,要成為哪個 view 的 child view。最後一個參數 attachToRoot 是 inflate 的 view 是否要 attach 到 root view,這會影響到回傳的是哪個 view。假如 attachToRoot 為 true,則最後回傳的 view 為 root view (就是第二個參數的 view);反之就是回傳 inflate 的 view。         第二個參數 ViewGroup root 需要特別說明一下,因為這會影響到如何 inflate 新的 view 出來。android 的 view 是有階層 (hierarchy) 的,因此 parent view 的屬性 (attribute) 會影響到 child view 。假如你是如以下兩種方式使用 inflate method的話: View view1 = LayoutInflater.from(mContext).inflate(R.layout.your_file, null) View view2 = LayoutInflater.from(mContext).inflate(R.layout.your_file, null, false)         因為沒有 root view,系統沒辦法把 inflate view 的屬性正確設定,因此系統會把 inflate view 的屬性設為 null,這會導致 inflate view 的屬性都非你所預期  (稍後會用 LayoutInflater source code 解說)。因此要很注意你 root view 是否要代 nul

            Deprecated API

                    當透過 IDE 使用 API,或是查 Document 時,常會看到一段途述:  This method was deprecated… 這是什麼意思呢?這是告訴我們還是可以使用此 method,但未來可能會沒有用、甚至是 在新版本的 SDK 會把這個 method 移掉 。         以 API level 11 出現的 Fragment  為例子,在使用時常會 override 一個 callback 叫 onAttach (Activity activity),但到了 API level 23 (Lollipop) 時,可以發現 onAttach (Activity activity) 被標記為 deprecated 了,取而代之的是 onAttach (Context context)。         像我個人寫程式不太喜歡出現 warning,而使用到 deprecated api 會被 Android Studio 檢查出來,我在用 Fragment 時就直接都換成 onAttach (Context context),結果程式在 api level 較低的手機就出現不符合預期的行為。Debug 了一陣子才發現 onAttach (Context context) 是新的 API,舊版本 SDK 當然沒有這個  API,自然就不會執行到該 API。         因此,雖然有些 API 被標記為 deprecated,但當你的程式還需要支援較舊版本時,還是得使用這些 API,假如要用的 API 在 Support Library  也有對應版本的話,我會建議用 Support Library 版本,因為放在裡面的 API 本來就是為了向下相容而設計的。以 Support Libaray 裡的Fragment 來說,onAttach (Activity activity) 一樣被標記為 deprecated,也一樣有 onAttach (Context context)  ,但它卻向下相容到 api level 4,因此為了向下相容性,使用 Support Library 是比較好的。 參考資料 1. Android Fragment 2. Android Support v4 Fragment 3. An