0

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?

pixelearth
  • 13,674
  • 10
  • 62
  • 110
  • Quoting myself from [your previous question on this subject](http://stackoverflow.com/questions/17004739/how-to-refer-to-a-resource-not-in-the-library-project-but-only-in-the-dependent), "Somewhere, the host project needs to be connected to this library. Wherever that is, pass the value. For example, put it as an extra on the Intent used to pass control to this activity from the library." – CommonsWare Jun 10 '13 at 21:14
  • This is actually a different issue completely. I'm wondering how to make code structures available in different parts of the application. – pixelearth Jun 10 '13 at 21:16
  • 1
    "This is actually a different issue completely" -- possibly, but the solution would seem to be the same. You need to have the library expose some sort of API, whether that be in the form of methods on classes, or extras on `Intents`, etc. – CommonsWare Jun 10 '13 at 21:18
  • No code is running on the app that can call any of those APIs or sent anything to with Intents. I'd like the Library Project to find out what it needs by inspecting a config file, or available class in the app. – pixelearth Jun 10 '13 at 21:54

2 Answers2

1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • All of the activities are in the Library. One activity is set in the Manifest to load automatically. The app doesn't need to 'call' anything. – pixelearth Jun 11 '13 at 19:32
  • @pixelearth: Then use the `` element I cite in the second paragraph of my answer. – CommonsWare Jun 11 '13 at 19:33
1

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.

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
  • I'm new to android. Where would I put this? In the library manifest? Also how would I access it from the activity? – pixelearth Jun 10 '13 at 23:19
  • 1
    @pixelearth This will answer both questions: http://developer.android.com/guide/topics/resources/more-resources.html#IntegerArray – MaciejGórski Jun 10 '13 at 23:23