Store large amounts of texts for Android app - android

I'm developing an Android app in which users will be able to write/save/modify potentially large pieces of text. I believe the amount of words will range from 10-1000. In the worst-case scenario, users will write a new piece of text everyday.
What is the best way to store these kinds of text data, holding in account the ability to easily modify saved pieces of text?

Store the data either as a file or in an sqlite database, if possible segment those pieces as separate records/files. For the loading part - there won't be any trouble of dealing with 1000 word within RAM, for example, if you load it inside a TextView. The limit to the size of text you allocate to your TextView is basically the amount of memory that you have.
I suggest testing your text editing view with ridiculously long texts at the end and if you see any issue (sluggish, runs out of memory etc), than you would have to take care of segmenting the document on your own. Hope this helps.

Best option Use sqlite database if you want to store data by day or by time. So, you can easily manage all your data.(if you looking for storage capacity then you can also manage your database in SDCARD(take backup in SDCARD, or create DB in SDCARD...etc.))
2nd Option store Data directly in SDCARD external storage(readable to user(He/She can Delete your data)).
you can use Encryption & Decryption in above both way.

Related

Best way to use AutoCompleteTextView with medium sized dataset of strings

If I want to use an AutoCompleteTextView as a search function to generate a list of strings (let's say about 1000-3000 strings) based on the text the user has currently inputted, would it be better to be loading these strings from an external database or having them stored in the internal SQLite database and loading the strings from there?
Is the amount of strings I plan on storing too big (each string will be about 10-20 characters long, they are constants and will never change) to be used in the SQLite database? How much would this slow down and/or bulk up my app? Should I just use the external database? Would the loading times be fast as the user is typing in a string?
I'm asking because if I can avoid using an external database I would prefer that since I wouldn't have to worry about the number of users accessing the database, maintaining it, and security issues.
would it be better to be loading these strings from an external database or having them stored in the internal SQLite database and loading the strings from there?
Depends on what you mean by 'better'. If you store them in a local database then the performance should be better, I recommend using indexes in this case. At the same time, this solution will require more memory although I think 3000 strings should be okay if they are just one-word strings.
Is the amount of strings I plan on storing too big to be used in the SQLite database?
Depends on what are those strings. If they are not too long then I think it should be fine. If each string contains a lot of text then I think this might cause problems while searching through them via SQL queries.
How much would this slow down and/or bulk up my app?
It shouldn't be noticeable, you can actually create a test for that, shouldn't take a lot of effort. Depends on your use case.
Should I just use the external database?
If those strings are like constants and they are not going to change, you can consider storing them in a local database, this should improve the performance versus the network-loading solution.
Would the loading times be fast as the user is typing in a string?
You can load the first set of data when they 'stop' typing. See my answer to similar question here: Best Practices for Handling Search
Once you load the list of data you can use this local cache for further searching, it should be fast enough so that user doesn't notice any delay.

Android data storage choice for a few fixed amount of entries, sqlite or sharedpreferences?

I wanna make an app kind of like Google keep, which has these features:
Storing the names, content, background color of every notes and photos (not including to-do lists, it's a little complicated), using TextView for notes, Custom View (TextView + ImageView) for photos;
Entries could change position with each other by drag and drop;
It could only save 10 entries at most. If there exists opening entry position, The app will fill the position with placeholder, and display all the 10 position in one screen (no scrollbar).
In my opinion, both method have some shortcomings for this situation:
Sharedpreferences: the amount of data is too much and kind of complex;
Sqlite: the data entries are limited. Besides, I think TableLayout is more suitable than GridView cus I want them display in one screen without scrollbar.
Then which data storage method should I choose, sqlite or sharedpreferences? Thanks for your help.
SharedPreferences is not suitable. As you note, it is not meant for that amount and complexity of data. As the name implies, it is meant for storing a users' preferences, not their data.
Note that SQLite support BLOB type that can be used for storing images, etc.
But you aren't limited to those two options. The third option would be to store your data in a file, in any format you choose, e.g. you could serialize your Java objects into a file. Since you will be dealing with a limited amount of data you don't necessarily need the capabilities of SQLite.
But on the whole, I think that SQLite is your best option. It is better then SharedPreferences for reasons given above, and better then the 3rd option because it is built into Android and is widely used.

Choosing Best Storage Type in Android

There are many similar questions about this issue but I have clear points about my question to ask you.
I am new at Android development and before only I developed small applications which store small sized data. For example country List, calendar, birthday reminder etc. I stored my small data in single XML file and I parsed it with easy methods. This was enough for me. But for my Mobile Application Development Course I took a project which will store huge static data.
Specifications of my project will like these:
There are about 200 entities.
Each entity has about 20 sub categories which they stored in text format.
Each sub category has about 30-sub categories which they stored again in text format.
Also for each parent entity I will have 2-3 image
If I calculate simply, I have to store 200 X 20 X 30 = 120.000 static data for my application and data does not change. This is only install and use application. Online data interaction is not necessary. (If there are some changes for data I will relase major updates in long periods of time.)
My question is about storing method.
Which way should I choose? SQLite or XML parsing? For your answer can you explain advantages / disadvantages for your choice?
Interesting project, although not necessarily realistic.
To manage a large amount of "static" data, you'll want a database. XML parsing forces you to store the data in memory, which means that you have to read it into memory on a regular basis. Remember that you can't count the in-memory data being around when the user goes to your app; Android may have destroyed your app previously.
On the other hand, you can use an SQLite database on disk directly from your app. It's persistent, even if your app goes away. You'll have to load the database once, when you install the app.
Consider wrapping your SQLite database in a content provider. This will, among other things, allow you to do asynchronous queries using a CursorLoader.

Android Performance : Flat file vs SQLite

There are few questions related to this topic on stackoverflow, But I didn't get the proper answer. I have some doubts on performance of flat files, Is it better to use flat files instead of SQLite ? Can anybody have performance statistics ? Or example of proper way to code flat file in android.
Aside from performance benefits, here's a simple list of advantages of using SQLite rather than flat file:
You can query items as you wish -- don't need to load all of them and select which ones you need.
Deleting records is a much less painful process. No rewriting of whole files into wherever.
Updating a record is as easy as removing or creating one.
Have you ever tried doing cross-referencing lookups on a flat file? Not worth it.
To summarize, it's every advantage a Database has over a text file.
It depends on your requirement.
If your storage data size is structured-bulky in size then i suggest you for SQLite. On the other hand if the data size is just a single or few lines then flat file is best option.
What makes difference between them is, SQLite stores data in structured format, so it will be easier to find a record from multiple set of records which is very tedious process in case of flat file.
However when if you are storing blob kind of data then it is suggested to use combination of both, SQLite and file system both. i.e. store the image/sound/video data as file format and store their path in SQLite.
Also visit this accessing performance.
SQlite definitely way better in terms of performance and this gets even more important as the size of your data increases.
I've been working on a flutter app where I needed to display a filtered list of items dynamically based on typed text. I initially used a json file to store data and would read and store relevant values into a list, then filter this list as the user types.
This worked just fine with a few items so I thought I was fine until I tested with a real dataset which contained over 150,000 items. Trying to filter a list this large as a user types crashed the app. I moved to a database solution and all my problems were solved. Instant filtering and no more crashes

Using a humongous database in an android APP

I am trying to use a database for my application which needs a list of all the words in Arabic language, unfortunately this database is very large in size, more than 200 MB, I've seen that the only solution for such a problem is using a web service or having my database online and download it on first use which is not practical in my case since this is a game and the user can play it while he's disconnected, plus the download size will be large and it will use alot of space on his phone. I couldn't find a way to make the size of my DB reasonable.
My question is if there is a way to shrink the size of the database knowing that all the data stored in it is of the type text.
I've noticed that the keyboard in my phone has an auto-complete feature, where is it getting the list of valid words from? Can i use it for my application?
You'll want to store your words in a prefix tree (or trie). It is a space-efficient structure for this kind of data.
For more info, see: https://gamedev.stackexchange.com/questions/4142/best-way-to-store-a-word-list-in-java-android
your database might have so much extra information included, for example grammar, inflections, comments etc. If this is the case, then re-create your database with only the limited data/columns you need to be used inside phone.

Categories

Resources