How to have code in my Library Project operate on configuration data in my android application?

StackOverflow https://stackoverflow.com/questions/17032947

  •  31-05-2022
  •  | 
  •  

Вопрос

I have 10 apps based of of one Library Project. I have an activity in the Library Project that shows a list of images. The images are different for every App, and are in the individual project. How can I create a data structure of the image data so that the Library Project activity can loop through it?

Это было полезно?

Решение

CommonsWare's answer seems like a good idea and I would try that first.

Another approach would be to create an empty integer-list inside your library:

<integer-array name="resources">
</integer-array>

and inside every project list drawables that would be actually used:

<integer-array name="resources">
    <item>@drawable/res1</item>
    <item>@drawable/res2</item>
    <item>@drawable/res3</item>
</integer-array>

This way you have a reference to it inside library and can loop over the list, that will override library's empty list.

Другие советы

No code is running on the app that can call any of those APIs or sent anything to with Intents

Then how is your library code ever going to get executed?

If the answer is "I am publishing components that go in the manifest of the hosting app", then use <meta-data> elements in the manifest to allow the hosting app to point you to an XML resource file that contains this configuration information. You can see this with app widgets, searchable activities, and so forth.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top