目前分類:Android (119)
- May 26 Sun 2019 15:03
Line 收不到訊息? Android 6 Doze mode 導致推播喚醒的 Activity 直接被 Automatic Destroy 的解決方法 』Willy's Fish教學筆記
- May 14 Tue 2019 07:39
Android 解決 Huawei 手機在 Android Studio 裡面無法印出 log, logcat 看不到 log 資訊』Willy's Fish教學筆記
- Apr 30 Tue 2019 13:57
Android 解決 SensorManager.unregisterListener() is not work,Sensor 取消監聽無效,指定為 null 也無法』Willy's Fish教學筆記
專案實作指南針功能時,需要註冊 Sensor Listener
關於 Sensor 的生命週期
我們通常會在 onResume 時開始監聽
但在 onPause 時就取消
以免太過消耗電力
今天打算用 command line 指令./gradlew assembleRelease
打包各 flavors 的 apk 時,出錯如下
======================
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
FAILURE: Build failed with an exception.
- Apr 27 Sat 2019 15:21
Android Gradle 使用 productFlavors 自配適各環境 (SIT、DEV、UAT、PROD...), 參數設定,與資料架構 folder structure』Willy's Fish教學筆記
開發一套已有大量使用者的 APP 時通常都要小心一點
為了程式的穩定性與品質
我們都會建立各種環境來把關
像是 dev 開發環境,sit 整合測試環境,uat 情境測試環境,prod 正式環境… 之類的
雖然每個公司的環境不一樣,但卻是大同小異的
- Apr 26 Fri 2019 10:09
Android APK 太大怎麼辦,限制超過 100MB,一招教你減肥縮小30% 』Willy's Fish教學筆記
Google 一直有個限制
apk 不能大於 100MB
基於解決這個限制
Google 提供了 APK Expansion Files 的方式來外掛資源檔
所以我們就可以把 res 裡面的東西額外分離出來
- Apr 12 Fri 2019 14:18
Android 升級 Gradle 3.x , implementation, compile, api 之間有什麼區別、差異與不同之處呢? What difference between 'implementation','api' and 'compile' in build.gradle?』Willy's Fish教學筆記
compile 在 2018年底已經不再支援了
所以升級 Gradle 成了必然
而升級到 Gradle 3 以上的朋友第一個遇到的問題應該就是下面這個
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
在嘗試使用 MVVM 架構時,使用 DataBinding 遇到了此問題 part2
一 Build 就會出錯,錯誤訊息如下
Found data binding errors.
****/ data binding error ****msg:Cannot find the getter for attribute 'android:background' with value type int on android.support.constraint.ConstraintLayout. file:XXX ****\ data binding error ****
我們很明顯的可以從訊息看出 background 的值 type 是 int
在嘗試使用 MVVM 架構時,使用 DataBinding 遇到了此問題
只要我進入目標 Activity 就會 Crush,出現下列錯誤
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxxxx.AroundCircleActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class layout
而出錯的地方是 setContentView
今天在試著引入 Butterknife 10.1.0 後發生的問題
錯誤訊息如下:
Manifest merger failed :
Attribute application@appComponentFactory
value=(android.support.v4.app.CoreComponentFactory)
from [com.android.support:support-compat:28.0.0]
AndroidManifest.xml:22:18-91 is also present
at [androidx.core:core:1.0.0]
AndroidManifest.xml:22:18-86
value=(androidx.core.app.CoreComponentFactory).
Suggestion:
add 'tools:replace="android:appComponentFactory"'
to <application> element
at AndroidManifest.xml:5:5-23:19 to override.
此錯誤訊息告訴我們 Manifest 合併時失敗
其實是 support v28 和 androidx 無法同時存在的關係
- Mar 22 Fri 2019 16:02
Android Material Design 的 SnackBar 使用教學、介紹、範例。可以不用 Toast 囉 』Willy's Fish教學筆記
Meterial Design 裡面有一個 SnackBar 的元件
此元件可以說是 Toast 的進階版本
都是用來呈現簡短的訊息的元件
由於 Toast 不符合 Meterial Design 的設計風格
所以才有 SnackBar 的出現
- Mar 18 Mon 2019 14:56
Android ViewTreeObserver 的介紹使用,與取得 View 寬高,解決 getMeasuredWidth = 0, getMeasuredHeight = 0 的問題 』Willy's Fish教學筆記
- Jan 15 Tue 2019 15:34
Android Sample Fingerprint API 指紋辨識功能教學、介紹與使用範例 』Willy's Fish教學筆記
- Jan 08 Tue 2019 15:46
Android 解法:Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute? / Unexpected end tag string 』Willy's Fish教學筆記
今天看到同事有報出以下錯誤
error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?
error: Unexpected end tag string
這是一個在 string.xml 中設定字串時要注意的一件事
- Dec 22 Sat 2018 13:25
Android 靈異事件:在 onClick() 裡印出 isClickable = false,setClickable() 無效? setOnClickListener的順序性? setEnabled() 特效藥?』Willy's Fish教學筆記
今天我們開發時發生了「靈異事件」
各位看倌請看一下這段 code
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
GG.d("RDBG:onClick() => view.isClickable()="
+view.isClickable()+" / id="+view.getId());
}
});
然後觸發點擊輸出如下
- Dec 03 Mon 2018 15:47
Android Activity & Fragment 傳遞資料的方法,二種傳值的基本方式教學 』Willy's Fish教學筆記
開發過程中,一定很常遇到傳值這件事
而傳值的方法也很多種,相關的議題也是讓人討論再三
今天我們就來談談 Acitivy 和 Fragment 兩種傳值的基本方式吧
1、Bundle
- Nov 29 Thu 2018 13:18
Android Studio 一樣相同的程式 code ,但模擬器、虛擬機會 crush 壞掉, 實體機卻正常的解決方法』Willy's Fish教學筆記
今天發生件怪事
明明 code 都一模一樣的,用同一份程式碼去 build & run
但用模擬器跑就會 crush,手機確卻正常啟動
模擬器移除 app 再重新安裝也無法解決
最後請教前輩的經驗,才知道和 Android Studio 有關係
- Nov 28 Wed 2018 11:33
Android 遇到 Application Installation Failed 該怎麼辦? 解決方法教學,造成原因介紹』Willy's Fish教學筆記
- Nov 26 Mon 2018 15:37
Android TargetApi、RequiresApi、suppressLint 的用法與差異,Error: Calling new methods on older versions 』Willy's Fish教學筆記
前篇我們提到了解決 Call requires API level 的 Annotation 不止一個
今天我們就來說說其差異性在哪
一共有三個 Annotation 要解說
// 此 class 需要 M 以上調用,否則會 crush
@RequiresApi(api = Build.VERSION_CODES.M)
@TargetApi(Build.VERSION_CODES.M)
@SuppressLint("NewApi")
public class FingerprintHelper { 。。。}
1、@TargetApi(Build.VERSION_CODES.M)、@TargetApi(23)