I would like to have a generic 'Chooser' activity - one which can be provided with abstract data source, extract data from said source, present the data in a
But that doesn't seem to work for me here, since I do not want to provide the actual data - I want to pass a reference to abstract data source, which can be queried (not unlike the Cursor).
Pass an extra or
Uri that identifies the abstract data source. Use that information to then query that data source.
For example, suppose that the "abstract data source" is a Web service. Your activity will need to know enough about the Web service to know what sort of data comes back, simply because the activity has to have rendering rules for that data (i.e., what to show for rows in the list). But, perhaps the actual URL for the Web service varies. Pass the URL as an extra, or as the "data" of the
setData(Uri.parse(theUrlThatYouWant)). Your activity can then use something like Retrofit to retrieve the data in a background thread and use the results in the list.
Since we have no idea what your "abstract data source" is, we cannot readily help you further. In general, what you are passing to the activity is some identifier that allows the activity to look up the data source. What you use for you identifiers, and for that lookup mechanism, is up to you and may tie into what the "abstract data source" is.
You are welcome to have generic UI populated by arbitrary data sources, but those arbitrary data sources cannot be passed around via an
Intent objects are designed to be passed across process boundaries. Your primary choices are:
Use inheritance and polymorphism. Have an abstract chooser activity that does most of the work, with subclasses that can obtain the data given simple identifiers.
Use some in-activity UI, such as a fragment, since you are no longer limited by
Intent structures and can pass around whatever is needed.