Android中AppWidget加载流程(二)
2011-09-20 17:34
483 查看
1. 用户长按Launcher弹出添快捷组件的Dialog,选择添加AppWidget,这时会打开一个Activity(AppWidgetPickActivity)显示系统中全部
AppWidget,单击某一个AppWidget后会做以下操作:
(1) 通过AppWidgetService获取一个最新的appWidgetId值。
(2) 根据获取的appWidgetId值,向单击的AppWidget组件发出APPWIDGET_ENABLED和APPWIDGET_UPDATE更新广播。并向
/data/system/appwidgets.xml中添加此AppWidget的基本信息。
2. 启动AppWidgetPickActivity(第1步中提到)时使用的是startActivityForResult()方法,所以在向所单击的AppWidget组件发出
APPWIDGET_ENABLED和APPWIDGET_UPDATE更新广播后会执行onActivityResult()方法,做以下准备工作:
(1) 将需要被添加到Launcher的AppWidget基本信息保存到数据库中。
(2) 根据查找到的appWidgetId值(整型值)创建LauncherAppWidgetHostView布局对象。
(3) 根据查找到的appWidgetId值(整型值)从AppWidgetService中获取RemoteViews对象(因为是第一次启动所以RemoteViews对象
为空)。
(4) 将获取到的RemoteViews对象的布局解析并设置到第(2)步中创建的LauncherAppWidgetHostView布局对象中。
(5) 将LauncherAppWidgetHostView布局对象添加到Launcher的WorkSpace中(因为RemoteViews对象为空,所以只在Launcher的
WorkSpace中占了一个位置)。
3. 在第1步中已经向需要添加到Launcher中的AppWidget发出了更新消息(注意:第一步和第二步是异步执行的),继续做以下事情:
(1) 每个AppWidget接收到广播后都会调用onEnabled()方法和onUpdate()方法,在onEnabled()方法中进行一些初始化操作,在
onUpdate()方法中创建RemoteViews布局对象并通过AppWidgetManager的updateAppWidget(int appWidgetId, RemoteViews
remoteViews)方法通知AppWidgetService对象用RemoteViews对象更新appWidgetId所对应的AppWidget.
(2) AppWidgetService接收到了appWidgetId和RemoteViews后,通过appWidgetId查找已经被添加到Launcher的
LauncherAppWidgetHostView布局对象,并将RemoteViews中的布局更新到LauncherAppWidgetHostView布局对象中。
AppWidget显示在Launcher中。
AppWidget,单击某一个AppWidget后会做以下操作:
(1) 通过AppWidgetService获取一个最新的appWidgetId值。
(2) 根据获取的appWidgetId值,向单击的AppWidget组件发出APPWIDGET_ENABLED和APPWIDGET_UPDATE更新广播。并向
/data/system/appwidgets.xml中添加此AppWidget的基本信息。
2. 启动AppWidgetPickActivity(第1步中提到)时使用的是startActivityForResult()方法,所以在向所单击的AppWidget组件发出
APPWIDGET_ENABLED和APPWIDGET_UPDATE更新广播后会执行onActivityResult()方法,做以下准备工作:
(1) 将需要被添加到Launcher的AppWidget基本信息保存到数据库中。
(2) 根据查找到的appWidgetId值(整型值)创建LauncherAppWidgetHostView布局对象。
(3) 根据查找到的appWidgetId值(整型值)从AppWidgetService中获取RemoteViews对象(因为是第一次启动所以RemoteViews对象
为空)。
(4) 将获取到的RemoteViews对象的布局解析并设置到第(2)步中创建的LauncherAppWidgetHostView布局对象中。
(5) 将LauncherAppWidgetHostView布局对象添加到Launcher的WorkSpace中(因为RemoteViews对象为空,所以只在Launcher的
WorkSpace中占了一个位置)。
3. 在第1步中已经向需要添加到Launcher中的AppWidget发出了更新消息(注意:第一步和第二步是异步执行的),继续做以下事情:
(1) 每个AppWidget接收到广播后都会调用onEnabled()方法和onUpdate()方法,在onEnabled()方法中进行一些初始化操作,在
onUpdate()方法中创建RemoteViews布局对象并通过AppWidgetManager的updateAppWidget(int appWidgetId, RemoteViews
remoteViews)方法通知AppWidgetService对象用RemoteViews对象更新appWidgetId所对应的AppWidget.
(2) AppWidgetService接收到了appWidgetId和RemoteViews后,通过appWidgetId查找已经被添加到Launcher的
LauncherAppWidgetHostView布局对象,并将RemoteViews中的布局更新到LauncherAppWidgetHostView布局对象中。
AppWidget显示在Launcher中。
相关文章推荐
- Android中AppWidget加载流程(一)
- Android中AppWidget加载流程
- Android中AppWidget加载流程(一)
- Android中AppWidget加载流程(二)
- 【Android AppWidget开发流程】
- Android:AppWidget开发流程
- Android Launcher源码研究(二) 加载app流程1
- Android Launcher源码研究(三) 加载app流程2
- 【Android AppWidget开发流程】
- Android基础学习之AppWidget(桌面小部件)
- Android 第三方桌面,怎么请求Widget的android.permission.BIND_APPWIDGET
- APP程序崩溃错误为Android.widget,textView cannot be cast to android.widget.button
- Android 之窗口小部件详解--App Widget
- Android的应用(APP)启动详细流程
- Android -- AppWidget 进阶篇
- Android入门——AppWidget及Broadcast的使用
- Android手把手教大家制作APP首页(下拉刷新、自动加载)
- Android中选取并绑定AppWidget
- No android.appwidget.provider meta-data for AppWidget provider 'ComponentInfo{xx}
- android 如何动态的加载类----app插件技术