4

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?

Sukumar Gaonkar
  • 147
  • 2
  • 12

1 Answers1

1
  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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thankyou soo much for such a quick and elaborate response. I will probably limit myself to available view. About building my own Parcelable data structure is there a sample project I can use as a guide, as I never done anything like this before – Sukumar Gaonkar Feb 14 '17 at 20:35
  • @SukumarGaonkar: In terms of building a `Parcelable` data structure containing commands to build a UI, I do not know if anyone on the planet has tried it, other than for `RemoteViews` itself. If you mean `Parcelable` in general, I am sure that there are tutorials floating around for it, though I do not have any handy. FWIW, I have a chapter on `Parcelable` in my book -- here is [the chapter preview](https://commonsware.com/Android/previews/writing-and-using-parcelables). – CommonsWare Feb 14 '17 at 20:49
  • I have limited my layout to the permitted Views, and they are laid out as expected, but I am unable to update them. E.g. I have pendingIntents attached to each button which trigger my plugin code, where I update contents of my layout. But these updates are not visible on screen. I suspect I need to call something like `updateAppWidget(thisWidget, rView);`. any guidance on updating laid out remote views? Thanks :) – Sukumar Gaonkar Feb 20 '17 at 17:51
  • 1
    @SukumarGaonkar: Typically, you update `RemoteViews` the same way that you create them in the first place. – CommonsWare Feb 20 '17 at 17:56
  • Are you suggesting I need to re-inflate and re-draw the update remoteView? are there any drawbacks of this on memory usage and performance? Thanks again for your prompt response :) – Sukumar Gaonkar Feb 20 '17 at 18:00
  • @SukumarGaonkar: Again, it is all really up to you. In the case of traditional uses of `RemoteViews` (home screen app widget, custom `Notification`), sending over a complete `RemoteViews` is the safest thing, as you are never quite certain what the state is, given that you only control one side of the relationship. In your case, if you are using `RemoteViews` between two apps that you control, you can do whatever you want, within the limit of what `RemoteViews` itself offers. – CommonsWare Feb 20 '17 at 18:08
  • 1
    @SukumarGaonkar: AFAIK, `apply()` on `RemoteViews` -- what your recipient probably uses to render it -- does not handle updates. However, there is nothing stopping you from using *something else* as a means of applying updates (e.g., send over a set of commands indicating how to adjust the state). Other than being limited by IPC, this is not significantly different than dealing with loose coupling between chunks of UI within one app (e.g., two different fragments). – CommonsWare Feb 20 '17 at 18:10
  • FYI the link on: This pair of sample projects demonstrates the process. 404s: https://github.com/commonsguy/cw-omnibus/tree/master/RemoteViews the parent is fine https://github.com/commonsguy/cw-omnibus/tree/master/ it just looks like the RemoteViews sample is gone. – MathiasTCK Aug 29 '22 at 19:16
  • 1
    @MK.: I must have removed those samples in the intervening years. I removed the reference to them from the answer. Thanks for pointing this out! – CommonsWare Aug 29 '22 at 23:30
  • Have you found much use for RemoteViews since? – MathiasTCK Sep 11 '22 at 01:12