I have the following question: I should create a chart in app activity. The first axis of this chart is temperature and the second is date when such temperature was. I am thinking of using SQLite for keeping this data, because I think that this data is easier to process. Or there is no need in it and it's better to use usual file. But how can I process the date if it keeps in format dd.mm.yyyy in such case?
Using Sqlite is fine.
Then use epoch for date/time. I.e seconds or mSec since 1.1.1970.
Visit https://github.com/PhilJay/MPAndroidChart that may help you in your app.
Sqlite would be a good to store all your data.
Related
I am building an app as part of a project and I am stuck at the moment.
Background: My team is making a "Time-Wasting" App, and the user can press buttons such as "study" to track their time spent on activities - so there will be lots of integers values in the growing ArrayList.
Task:
Store a growing Arraylist(integers) in the app store and retrieve the values for calculation and graph display purposes.
Problem:
I have looked so far how do to this, but I am a bit stuck. Do I use SharedPreferences, the internal app storage or something else. Also, I have a hard time finding code that I could look at and follow what it is doing.
I need:
An efficient way to store the ArrayList (integers) in a storage place and retrieve it for my app. Any suggestions what would be best and where would I find the code for that?
I looked for about 2 weeks through videos and a through stack overflow but I am still stuck and not closer to how I should store this data type in my app.
Thanks, any help much appreciated :)
My opinion avoid the array list and use a database.
It will allow your app to grow including storing extra information along with the time waster including when they chose to do it, how long , etc.
I recommend Room Database it is an ORM for Sqlite it is super easy to use and there is plenty of documentation on implementation as it's apart of the Android Jet Pack.
If you are really stuck on using a list you can use SharedPreferences it doesn't handle ordered lists but you can store your list as a json string.
I am using sugar record for db in android. I have to fetch all records from table, near about 20000 records in table. It takes time 6-8 seconds. So lenghtly process.
List<Hospital> hospitalList = Hospital.listAll(Hospital.class);
Please help me how can minimize 1-3 sec.
Is it available alternate solution.
Note: We've not been maintaining SugarORM for a while now. I'd suggest you migrate to Android Room. It's a decent library, supported by Google.
If you have to use Sugar ORM, try using the find() methods, which give you access to an iterator. That way, you can control the data load and transformation.
Try to also look for ways you can limit loading of records, eg: pagination. Loading 20000 records at one shot will take some time any way.
I am a working on a project in which I retrieve data from facebook about friends of the user. Friends details vary some times while at the other times they are the same as the one stored in the db.
I can use the replace command to make sure that the db is consistent with whatever information I retrieve from the facebook.
My question is how efficient this technique will be? In other words, I can use two techniques:
One is to use the replace command and replace the complete record blindly
Second is to first check whether there is any difference from the record saved in the db and update only the fields that have changed
Which of these approaches is going to be more efficient?
I've found that queuing up a number of sqlite commands in a row is much more efficient than is doing anything else in between, even just comparing a few values.
I'd strongly recommend that you just do an update command. SQLite is fast.
My observation is that SQLite is always way faster than I am. So let it do the heavy lifting and just dump the data at it, and let it sort out your updates.
For example, I was searching through about 7,000 records. I pulled the records out into an array, did a quick check for one field, and separated it into two arrays. This was taking me about 5 seconds. I replaced it with two separate SQLite queries that each had to go through the entire data base. The revised dual query takes about a quarter second, near as I can tell, because its so crazy fast.
I've had similar speed luck with Updates in my big database.
I'm pretty new to android can some one give me a better idea which one is a better way to save 2 edit texts on activity 1 and 24 edit texts on activity 2.
i need to save it with date / time stamp
and
be able to open by linking with onClick of a button.
what is the best option: shared preferences, sql db or file?
Please help me out here.
Really it depends on what your application is going to do with that information and how you intend to use it.
Based on what you've briefly described, I'd recommend using an SQLite DB (with or without a Content Provider) to store the information just based on the fact that you're looking for a date/time stamp. Plus, it gives you a lot of flexibility going forward and it's not like there is a ton of overhead in that approach.
Shared Preferences are great too, but mainly are for key/value pairs and aren't nearly as flexible.
Last but not least, this question has some good info on using SQLite DB on Android and the differences in using a content provider vs. not.
I have a date/time that I get from a sqlite database and want to show in my Android app. I want it in the format :
9 November, 12:12. How do I do this? Is it best to format it before or after I enter it into the database?
See the answers to this question.
In your database, I would suggest you keep timestamps in there rather than the formatted strings. That way your program would still work if you decide to change the format later.