2013年7月21日 星期日

Git Diff Changed File Between Two Commit

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT COMMIT1 COMMIT2

將其中的 commit1 和 2 換成想比較的兩個 commit 即可。


如果只想複製出有更新的檔案
cp $(git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT COMMIT1 COMMIT2) PATH_TO_TARGET

Android Scan File Cause Global Reference Table Overflow (max=51200)

Android 4.x (版本不確定,已知版本 4.1.1、4.2.2),如果極端大量且快速的執行寫檔後馬上 scanFile 的動作,會造成 JNI ERROR (app bug): global reference table overflow (max=51200),詳細原因見官方 Issue:Issue 53914

如果遇到這種問題,就在最後再執行一次完整 scanFile 避掉,而非每存一個檔案就進行一次 scanFile 。

2013年7月17日 星期三

Android Context.startActivity From Uri Must Catch ActivityNotFoundException

如果 Intent 是用 Uri.parse 出的,在 startActivity 時請一定要 try catch ActivityNotFoundException。

例如:大部分的 Android 裝置都會有 Google Play,但是有些可能是白牌手機之類的,這時候如果想要去呼叫 Google Play 就會出現 ActivityNotFoundException。

所以如果不想管這麼多,就是只要用 Uri 或甚至是 package name 去 startActivity 的都要處理,除非有先用其他方式檢查過要開到的 Activity 是否存在。

2013年7月16日 星期二

Android Notification PendingIntent Received Old Intent

在 Android 中遇到點了 Notification 但是 Activity 卻的 onNewIntent 收到舊的 Intent 的狀況。

有兩種解法,各有各的用途和適合情況。

1. 在 PendingIntent.getActivity(context, requestCode, intent, flag) 的 flag 傳入 PendingIntent.FLAG_UPDATE_CURRENT

這種作法會在 requestCode 相同,但收到多個 Notification 時,只會保留最後的 PendingIntent。
官方文件說 requestCode 沒有用到是騙~人~的!
適合用在如只需要保留最後最新的資訊用到。

2. 在 PendingIntent.getActivity(context, requestCode, intent, flag) 的 requestCode 傳入 count

這個 count 是用來計算這是發第幾個通知。通常會和 NotificationManager.notify(count, pendingIntent) 用同一個。
這適合用在每則通知都要傳入不同的通知訊息內容時使用。

2013年7月4日 星期四

GenyMotion - The Faster Android Emulator


GenyMotion 是一個 Android 的模擬器,不像 Google 提供的慢吞吞模擬器,速度快很多。
裡面的映像檔有提供諸如:Nexus One、Nexus S、Galaxy Nexus、Nexus 7...等等各種尺寸的映像檔。也有 Google Play 可以讓你下載程式回來用,換句話說測試或是想拿來轉轉神魔之塔也可以用這個。
目前還沒開始收費。
安裝方式:
1. 先下載安裝 Virtual Box 的 MacOS 版,官網:https://www.virtualbox.org/wiki/Downloads
2. 下載安裝 GenyMotion,官網:https://cloud.genymotion.com/
註冊時,這個帳號之後用來下載映像檔也會用到。

Have a nice emulator :p