Reputation: 11
I would like to have all my Activities (7 to 10 different screens) submit data to a "controller" (sorry if I'm miss using the term).
Inside said controller data would either be uploaded or saved to data for uploading when no internet.
The controller would do checks and processing such as:
My goal is to have Activities do nothing more than collect the data and call the appropriate method (with a data object) asynchronously. The controller would know how to process the data for uploading or saving in the database.
Would placing these methods in an extension of Application be a bad idea?
It was mentioned that depending on application size this is feasable, but there could be better solutions.
Upvotes: 0
Views: 43
Reputation: 3337
Depending on the size of your project, that would be a suitable idea. However, there are some other ways you should know before choosing the method you're actually implementing:
ContentProvider
for your data, an AccountAuthenticator
and then sync to the server using an SyncAdapter
. Advantages are a good abstraction, independence from activities and many built-in features (for example: Android executes your code without a big battery life impact). However, implementing all the stuff is quite much work at first. If you don't want to use the ContentProvider
, the same technique works with a stub implementation as well, the same goes for the AccountAuthenticator
.Service
, probably IntentService
, for your uploading needs. Advantage is that the Service has an independent lifecicle and thus is not directly related to your Activity; a Service can get restarted if it has been killed by the system. Still more work than just using some static methods.AsyncTask
s can send their result directly to the activitiy that started it. However not suitable for long-running tasks.These are the ones that popped into my mind, there might be some others, too. Feel free to add/suggest additonal ones.
Upvotes: 1