RemoteViews应用与原理:通知栏和桌面小部件- https://blog.csdn.net/feather_wch/article/details/79175518
理解RemoteViews- https://www.jianshu.com/p/23041852bd85
-- 跨进程更新View;RemoteViews实现和使用场景: 通知栏、桌面小部件
RemoteViews是一种远程View,可以在其他进程中显示,为了能够更新它的界面,RemoteViews提供了一组基础操作用于跨进程更新它的界面。
RemoteViews主要用于通知栏和桌面小部件的开发。通知栏主要通过NotificationManager的notify方法来实现;桌面小部件则是通过AppWidgetProvider来实现的,AppWidgetProvider本质上是一个广播。因为RemoteViews运行在其他进程(SystemService进程),所以无法直接更新界面。
/**
* 用于获取状态栏的高度。
*
* @return 返回状态栏高度的像素值。
*/
private int getStatusBarHeight() {
if (statusBarHeight == 0) {
try {
Class<?> c = Class.forName("com.android.internal.R$dimen");
Object o = c.newInstance();
Field field = c.getField("status_bar_height");
int x = (Integer) field.get(o);
statusBarHeight = getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
}
}
return statusBarHeight;
}
RemoteViews作为远程View组件,主要用于跨进程更新界面,适用于通知栏和桌面小部件开发。通过NotificationManager实现通知栏功能,而桌面小部件则利用AppWidgetProvider进行更新。由于运行在SystemService进程,无法直接更新界面,因此提供了特定的基础操作来完成这一任务。

601

被折叠的 条评论
为什么被折叠?



