RemoteViews原理分析及应用

RemoteViews原理分析及应用

ID:40564198

大小:590.00 KB

页数:21页

时间:2019-08-04

RemoteViews原理分析及应用_第1页
RemoteViews原理分析及应用_第2页
RemoteViews原理分析及应用_第3页
RemoteViews原理分析及应用_第4页
RemoteViews原理分析及应用_第5页
资源描述:

《RemoteViews原理分析及应用》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、RemoteViews原理分析及应用RemoteViews基本概念RemoteViews乍一看名字似乎也是一种View,实则不然,它并不是View。来看RemoteViews的定义及官方说明:/***Aclassthatdescribesaviewhierarchythatcanbedisplayedin*anotherprocess.Thehierarchyisinflatedfromalayoutresource*file,andthisclassprovidessomebasicoperationsformodifying*thecontentoftheinflatedhiera

2、rchy.*/publicclassRemoteViewsimplementsParcelable,Filter{……}我们可以得到以下几点结论:RemoteViews只是一个实现了Parcelable和Filter接口的类,而并非继承自View。RemoteViews用来描述可运行在其他进程中的视图结构,但RemoteViews本身不是视图,只是一个描述类。RemoteViews描述的远程视图需要通过layout资源文件定义。RemoteViews类提供了一系列修改远程视图的方法。现在我们对RemoteViews应该有了一个大概的认识,它可以跨进程来显示和更新视图。RemoteVie

3、ws主要有两个应用场景:自定义通知栏桌面小部件本文最后会给出RemoteViews的应用实例,接下来我们先分析RemoteViews的实现原理。RemoteViews原理分析构造函数RemoteViews提供了多个构造函数,如:publicRemoteViews(StringpackageName,intlayoutId){}publicRemoteViews(StringpackageName,intuserId,intlayoutId){}publicRemoteViews(RemoteViewslandscape,RemoteViewsportrait){}publicRemot

4、eViews(Parcelparcel){}以一个最常用的构造方法为例:/***CreateanewRemoteViewsobjectthatwilldisplaytheviewscontained*inthespecifiedlayoutfile.**@parampackageNameNameofthepackagethatcontainsthelayoutresource*@paramlayoutIdTheidofthelayoutresource*/publicRemoteViews(StringpackageName,intlayoutId){this(getApplicati

5、onInfo(packageName,UserHandle.myUserId()),layoutId);}由注释可知,第一个参数为包名,第二个参数为布局资源文件的ID,接下来会调用:/***CreateanewRemoteViewsobjectthatwilldisplaytheviewscontained*inthespecifiedlayoutfile.**@paramapplicationTheapplicationwhosecontentisshownbytheviews.*@paramlayoutIdTheidofthelayoutresource.**@hide*/prot

6、ectedRemoteViews(ApplicationInfoapplication,intlayoutId){mApplication=application;mLayoutId=layoutId;mBitmapCache=newBitmapCache();//setupthememoryusagestatisticsmMemoryUsageCounter=newMemoryUsageCounter();recalculateMemoryUsage();}同样也很简单,第一个参数为远程视图展示内容所属的Application信息,第二个参数为布局文件ID。该构造方法主要是初始化mA

7、pplication与mLayoutId,其他代码为图片缓存及内存计算的一些逻辑。核心属性字段RemoteView有如下几个比较重要的属性字段:/***Applicationthathoststheremoteviews.**@hide*/privateApplicationInfomApplication;/***TheresourceIDofthelayoutfile.(Addedtotheparcel)*/privatefinalintm

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。