开发者

Is this a good idea to create a service to make all the hard work for the activity?

Is this a good idea to create a Service that make all the hard work for the Activity. IE, the Activity will just care abo开发者_如何学Cut the interface and for calling the services, and other functionalities it must need, and the service will be the 'tool' that will work for the Activity.


Yes, it's... I recommend you to watch this video:

Developing Android REST client applications

That video talks about REST client apps, but the same technique has been proved to work on many other situations.


Meh. Encapsulating access to data can be a good idea, especially since it makes it easier to test and gives you an opportunity to cache data. But don't over-engineer. The approach outlined in the video linked by Cristian is overkill for many (most?) apps. In many cases good 'ol AsyncTask is good enough for most "hard work". If not, then definitely consider an IntentService as your next option. I would consider both of those options before going the full Service route complete with AIDL and bindings. I usually only go the latter route if I need a background Service (for Notifications or data-sync, etc.) and it shares data with the main App (which is often the case.) As for the ContentProvider patterns from the video ... Personally I only think these are worth doing if you don't want to control the caching of data (or the data is not cached, and the device is really the system of record) and you want to expose the data to other applications. I would almost always favor exposing my App code to a Service interface instead of a Cursor. Seriously, don't over-engineer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜