RemoteView主要使用场景是通知栏和桌面小部件,可以跨进程更新界面
- 自定义通知用到RemoteView,更新图片文字需要用到setTextViewText和setImageVIewResources,如果需要增加点击事件就需要使用PendingIntent的setOnClickPendingIntent。
- AppwidgetProvider在桌面小部件应用中是一个广播的存在。
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/widget"
android:minHeight="84dp"
android:minWidth="84dp"
android:updatePeriodMillis="86400000" >
</appwidget-provider>
https://developer.android.com/guide/topics/appwidgets/index.html
其中AppWidgetProvider中的几个回调方法:onEnabled,onDisabled,onDeleted,onUpdated会自动被其onReceive方法在合适的时间调用,当广播到来以后,AppWidgetProvider会自动根据广播的action通过onReceive方法来自动派发广播
3. pendingIntent区别于intent,不是立刻发生的,用于将来某个特定时刻,可以通过send和cancle来取消。支持三种特定意图,启动activity,启动service和发送广播。pendingIntent有四种不同的flag对应不同的操作。
4. RemoteView只支持特定的layout和view,因为没有提供findId,只能通过一系列的set方法完成view的访问。大部分set方法通过发射完成。但是RemoteView没有完全通过binder去完成所有跨进程的操作,更新text时使用一个arraylist将action对象缓存起来,到最终通过applay方法实现action加载更新view。,而reapply只负责更新。
5. 例外pendingIntent只支持view的单击事件,想要给listivew或者statckview必须结合setpendingintentTemplate和setOnClickFillIntent组合是使用。