본문 바로가기

:::::: STUDY ::::::/Android

AppWidget 관련

AppWidget 관련


appWidgetProvider

public void onEnable(Context context)

: app widget 처음 생성될 때 호출함. 위젯을 여러개 호출해도 처음 한번만 호출됨.


public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)

: xml에 있는 updatePeriodMillis 값에 따라 주기적으로 호출됨. 위젯을 처음에 호출할 때도 호출됨.

(Configuration activity가 따로 있다면 처음에 호출되지 않음)

보통 여기서 핸들러를 사용해서 작업을 수행함.


public void onDeleted(Context context, int[] appWidgetIds)

: widget host로 부터 삭제될 때 호출됨.


public void onDisabled(Context context)

: 위젯이 삭제될 때 호출됨. onEnable처럼 여러개의 위젯이 있을 때, 마지막 위젯이 detach될 때 호출됨.


public void onReceive(Context context, Intent intent) 

: 일반적인 브로드캐스팅 리시버. 내용은 미리 구현되어있어서 굳이 구현할 필요성은 없으나,

필요에 따라 implement를 해서 추가시켜주면 됨.


================================================================

appWidget에서 사용 가능한 뷰

- FrameLayout
- LinearLayout
- RelativeLayout
- AnalogClock
- Button
- Chronometer
- ImageButton
- ImageView
- ProgressBar
- TextView

위젯의 레이아웃 크기
- 홈 스크린은 4x4 셀의 격자이다.
- 각 셀은 최소 74dpx74dp 
   (dip: Desinty Independent Pixels, 관련글 링크 : [Android] 디자이너와의 협업을 위한 몇가지 팁)
- 위젯의 크기는 아래의 공식으로 구한다.
   위젯의 최소 크기(dp) = (셀의 갯수 * 74dp) - 2dp(패딩값)

===================================================================

updatePeriodMillis 관련

위젯 업데이트 주기를 위한 updatePeriodMillis........ 이런 ㄱㄱㄲ ㅡㅡ;;

1초 후 업데를 위해 1000을 넣어주면 업데가 안됨. 이유는

최소가 30분이다. 아마 배터리와 ap관련 때문이겠지만... 좀 적어두던가..( ㅡ_-)

developer.android.com에 가야지만이 보인다..(http://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html)

이렇게 Note: Updates requested with updatePeriodMillis will not be delivered more than once every 30 minutes.

잘 알고 판단하자....

30분 이내에 할려면..timer, thread, handler 등등... 사용해서 하면 될 듯...