Android: Cache XML file from RSS feed

I just started making my first Android app, which happens to be RSS Reader. I worked a bit on this, but did not see a clear link. What I want to do is cache the xml file (feed file) on the SD card, so when the phone is offline, the user can still watch the channel, automatically telling the application to search for it when the network is not found. Now I have an image caching mechanism, but I'm wondering how to use it for other files, as it was specified only for images that convert it to Bitmap using HashMap ().

+4
source share
1 answer

I think the preferred way (just as Umakant Patil commented on your question) is to store data in a SQLite database. Usually you write a background service that updates your database with server-side data from time to time. Your application will always read only from your SQLite database. Please note that the service and the application, as a rule, live their lives independently of each other (your application will never contact directly with your service).

This procedure is also somewhat more secure from an architectural point of view. Your application will never be affected by network connections or synchronization issues due to network traffic. It will only use data and database access on your local device.

TIP # 1: You can transfer an entry to AlarmManager, which will wake up your service at a specified interval. Your service will synchronize your database with the RSS source, and then kill yourself (saving resources is always good :-)

There is a good example in the Android application: http://developer.android.com/reference/android/app/Service.html

And about content providers here: http://developer.android.com/guide/topics/providers/content-providers.html

TIP # 2: Please note that you do not need a content provider to contact your database. The content provider is good to be if you want to "standardize" your connection to the database. Perhaps several components of your application should be able to access it or even several applications, then itโ€™s good to use the already defined โ€œde facto standardโ€ way of accessing the database.

+4
source

Source: https://habr.com/ru/post/1336248/


All Articles