2011年10月28日 星期五

access UI thread

Some ways to access ui thread from other thread

1.Activity.runOnUiThread(Runnable)
2.View.post(Runnable)
3.View.postDelayed(Runnable, long)
4.Handler
when start service, we can use handler+message to access UI thread. Create a Handler in UI thread, and register this Handler in service. Send message to Handler in service, so we can access UI thread by Handler.

5.AsyncTask

Make sure that you access the Android UI toolkit only on the UI thread. 另外service也是run在UI thread之中,所以可以access UI.

service life cycle
1. if start service by Context.startService().
onCreate()->onStartCommand()->onDestroy(). 直到呼叫Context.stopService or stopSelf(). 如果多次呼叫startService. 只要呼叫一次stopService, 則所有呼叫的service都會停止。但service所create的thread不會停止,記得要在onDestroy中停止自己create的thread。

2. if start service by Context.bindService()
onCreate()(只有第一次啟動該service時才會呼叫)-> onDestroy()

2011年10月13日 星期四

Android Log

main log $adb shell logcat -b main -v threadtime
system log $ adb shell logcat -b system -d *:i
kernel log $ adb shell dmesg (or adb shell cat /proc/kmsg)


system app
/system/app
user app(internal storage)
/data/app
user app(external)
/mnt/asec
/mnt/secure/asec

set system log level per application

       adb shell setprop log.tag.XXXX VERBOSE