java - Passing 'data source' between activities -


i have generic 'chooser' activity - 1 can provided abstract data source, extract data said source, present data in listview , return selected item calling activity. akin ringtonepickeractivity.

what can't figure out how pass generic data source 1 activity another. have seen far in term of sharing data between activities passing data through intent's extras. doesn't seem work me here, since not want provide actual data - want pass reference abstract data source, can queried (not unlike cursor).

the point i'd emphasize i'd chooser agnostic of actual source of data - abstract data source provide methods getnextitem, getitemname, getitemvalue. best models of can think of cursors or iterators - purely abstract mechanisms of iterating on set of data.

since activities of application hosted in same process, should possible? 1 thing do not want have global data source variable inside application, multitude of reasons (one of them being fact running multiple chooser activities multiple data sources) - want provide data activity being started @ start time.

is possible? terribly misguided? there better way?

but doesn't seem work me here, since not want provide actual data - want pass reference abstract data source, can queried (not unlike cursor).

pass or uri identifies abstract data source. use information query data source.

for example, suppose "abstract data source" web service. activity need know enough web service know sort of data comes back, because activity has have rendering rules data (i.e., show rows in list). but, perhaps actual url web service varies. pass url extra, or "data" of intent (via setdata(uri.parse(theurlthatyouwant)). activity can use retrofit retrieve data in background thread , use results in list.

since have no idea "abstract data source" is, cannot readily further. in general, passing activity identifier allows activity data source. use identifiers, , lookup mechanism, , may tie "abstract data source" is.

you welcome have generic ui populated arbitrary data sources, arbitrary data sources cannot passed around via intent, since intent objects designed passed across process boundaries. primary choices are:

  1. use inheritance , polymorphism. have abstract chooser activity of work, subclasses can obtain data given simple identifiers.

  2. use in-activity ui, such fragment, since no longer limited intent structures , can pass around whatever needed.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -