问题
I'm trying to realize an Android home screen widget. I am interested to know why I should use RemoteViews in implementing widgets?
回答1:
Refer this link site.
Creating the App Widget layout is simple if you're familiar with Declaring Layout in XML. However, you must be aware that App Widget layouts are based on RemoteViews, which do not support every kind of layout or view widget.
A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:
FrameLayout
LinearLayout
RelativeLayout
And the following widget classes:
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
Descendants of these classes are not supported.
回答2:
Most of the time Widget is hosted within another application, like Launcher, which is run within that parent application's process.
RemoteViews describes a view hierarchy that can be displayed in another process. The hierarchy is inflated from a layout resource file, and this class provides some basic operations for modifying the content of the inflated hierarchy.
The main reason behind this choice is related to security and performance.
回答3:
RemoteViews is used for the app widgets. They are part of separate process but bind to the main process i.e. why when we click over widgets it redirects to the associated application with more detailed information.
来源:https://stackoverflow.com/questions/5752445/why-should-i-use-remoteviews-for-android-home-screen-widgets