androidandroid-viewremoteviewandroid-remoteviewandroid-messaging

Is it possible to Inflate RemoteViews in other application?


I am developing two android applications, one being the baseApp and other serving as a pluginApp. The aim is to extend the functionality of the baseApp when its corresponding plugin is installed. The pluginApp will contain XML layout files which will contain 'new_layouts' which I need to display in the baseApp. Is there a way to pass the new_layout to the baseApp from pluginApp via Inter Process Communication or something similar?

I tried below approach with no luck I wrapped the layout file from pluginApp as a 'RemoteViews' object and passed it to the baseApp, but when I inflate it into baseApp I get an error saying

android.view.InflateException: Binary XML file line #9: Class not allowed to be inflated android.widget.EditText

Note: The 'new_layout' contains an EditText among other elements with EditText being the first child.

I have never used RemoteViews before and don't understand their purpose yet.

Please guide me on 1. whether Using view from one app into other app is possible? 2. Can RemoteViews be used for this purpose? If yes then how? 3. Why am I getting the error and what does that indicate?


Solution

    1. whether Using view from one app into other app is possible?

    Not directly.

    1. Can RemoteViews be used for this purpose?

    Yes.

    1. Why am I getting the error

    Because EditText is not one of the few widgets supported by RemoteViews.

    what does that indicate?

    It indicates that you have three choices:

    1. Limit yourself to the widgets supported by RemoteViews

    2. Do not try to share UI between apps

    3. Implement your own RemoteViews-like system

    In the end, a RemoteViews is merely a data structure that describes how to build a UI and how to send back very coarse-grained events (e.g., clicks, via a PendingIntent). There is nothing, other than time and expertise, stopping you from creating your own Parcelable data structure that describes how to build a richer UI than RemoteViews supports.