Saving multiple bits of data to be later retrieved on demand? - java

Trying to make an app in android studio that works as a fitness helper/tracker. On a daily basis and multiple times a day, the user enters data regarding their diet/exercise. Prior to doing so, the user selects which day they're currently on, making the data they input specific to the chosen date. I want to give users the ability to retrieve any available data for a specific day on demand.
I don't quite think sharedPreferences would work, so I was thinking about just saving to internal storage as a text file. The problem is that 1) with all the different files that would be created for even a single day, I feel that it would get messy and 2) I'm not sure how how to retrieve the specific file I'd need, parse it, then output the parsed data graphically if I'm only using a single constructor to make each text file.
I haven't yet delved deeply into using a SQLite DB, it seemed somewhat excessive for this, so I'm hoping someone can either help me figure out a better way to solve the problem or enlighten me as to a more efficient method.
Thanks in advance!

Related

How to pull data on daily basis every day in Java?

I've an app that i need to sort out.
The problem is with the timer that needs to update the fields on daily basis.
The data needs to be pulled from Excel file and stored in and then displayed according to the date of the file.
Please find the link to the picture which gives you an idea of what i am trying to do.
If someone could help me please feel free. I have already asked the question in depth and just need this part for the timer maybe if someone can do that then i might try that and then see if it works if not then maybe need the whole app to be fixed?
[Picture of the App][1]
many thanks for your time in advance.

Is SharedPreferences suitable, or is there a better alternative?

I am trying to become familiar with android application development. I am trying to make a simple app to learn the basic skills, but I am not sure how to handle this part of the app. Therefore I need advice about how to go further.
I have a simple app with a button and a textview with 0 on it: the score. When the button is clicked, score goes up by 1 (by simple java code). When I close the app and restart, the score is 0 again.
What I want: When closing the app, the score must be saved, so that the same score appears on restart. For example, like that egg that you have to click on a million times. If several users had the app, everyone should have their own score (of course). The number should therefore really be linked to phone/account.
I already read about sharedpreferences. It sounds like what I'm looking for: Storing variables. However, I don't know if this is suitable for what I want to use it for. The score should never be lost for that specific phone/account. It may not be possible for the user to adjust the score himself (except by clicking on the button).
My question: Is sharedpreferences suitable for what I want to use it for, or is there a better alternative?
SharedPreferences is used to store small pieces of data locally on your device. So, if the user Uninstall the app or Clears App data, the the data you store in SharedPreferences will be cleared.
If you are okay about data being lost on Uninstall/ Clear Data, SharedPreferences is surely the best way to store such small piece of information as using an Online database is quite an overkill for such small piece of data.
The score should never be lost for that specific phone/account.
But according to this, it seems like don't want to lose the data even if the user Uninstall/Clear Data, clearly you have to use a Cloud Database like Firebase Real-time database/ Firestore.
If you want users to Login/Sign Up, you have to use Firebase Auth otherwise, you can simply store data as PhoneNumber : Score key-value pairs on Firestore.
Hope it helps

Best way to store text data in an android app?

I've made an Android application which contains most used German words and sentences. The application contains a CSV file which stores all the data.
Currently it is working as expected but I want to ask if there is a better way to store such data directly in the app?
I'm also thinking about the ability to update the data via internet like adding new words and sentences.
Thanks!
Miretz
If you want to modify the content (update, remove etc.) I would suggest using SQLite DB which has a pretty nice built-in integration with the Android platform.
There are 2 types SQLDatabaseLite and SharedPreference. Major difference between both is that one is organized and the other not so.
If you need a quick use of a storage facility within your app for example changing text sizes between activity SharedPrefference works best for you.
If you have a complex database system where you need more than one data to be saved for a particular event SQLDatabaseLite is for you example of this is spreadsheet of data for customers; Name, Phone Number, etc.

Convert Large Switch to Hash (Or Other Recommendation)

I currently have an Android application that displays a schedule for a ferry boat. The application can display the full schedule (just a giant list), but the selling point in the application is it will display when the next two ferries are departing and how long from the current time that departure is.
I am relatively new to Java and currently use large Switch() statements in my code. Basically it gets the current phone time and compares it to all of the times in the schedule at which point it displays the next two departure times and then calculates the difference between current time and the departure times.
I am sure that a switch statement is not the best idea for speed purposes as well as code changing purposes. For example if one time changes its a bunch of lines of code to go in and fix for that one time change. Also if the entire schedule changes everyone has to update their app for the time change to take effect. My ideal situation would be to store a file somewhere on my webserver that could be downloaded and inserted into a hashmap (I think is the correct term) that would load the new schedule if there was a time change.
Not sure how confusing this is, but it would be greatly appreciated if someone could explain how I might use a hashmap or something else you might recommend to get this task accomplished. Currently the variables are the two ferry terminals as well as the day of the week since the schedule changes per day (monday, tues-friday, saturday, sunday).
Below is a screenshot of the application so you can understand it if my post wasn't clear. Thank you in advance.
Screenshot:
Store the schedule objects in a sorted array. You can then binary search the array for the first value greater than the current time. You'll probably use some parent array consisting of the location and applicable day of the week.
You can easily write that kind of data structure to a file that is read & parsed by the application for updates instead of being compiled into the code.
Details of this? First, understand resources in Android. If no updated schedule exists, fall back to the default resource.
Second, use an HTTP head request to check if a newer file exists. If it does, parse, download & save state. Saving Android Activity state using Save Instance State.
Finally, XML is handy for data distribution, even if it's not fast. Everybody understands it and it's easy to update or hand off.
<ferry location=0 time=2045>
<day>1</day>
<day>2</day>
<day>3</day>
<day>4</day>
<day>5</day>
</ferry>
<ferry location=0 time=0800>
<day>6</day>
</ferry>
You will need something like a database to hold the schedule data. That will help you to seperate code from data. I'm not familiar with Android but i think there is a interface to sqlite database on the device.
Further, as this is an application on a small device you may connect to the schedule database on a server thru the internet connection. That way you have to maintain schedule data only in one place (on the server) and clients will use always up to date data.

Getting data/information for android app use

I have been wondering about this, which is why I have put off learning app development for so long. Let's say I was making a school timetable app, that all the user had to do was enter the name of their course, and then the app shows the timetable for that course..
The questions is can I get information from the college or do I have to hard code it into the database myself?
How does one get information to use if they need it?
Thanks
It depends. Does the college provide you an interface you can use? Probably not one that was meant to be used by a third party app.
If not, then you have to somehow get the information into your database. Either per parsing their online HTML schedules or inputing it by hand (obviously always one of the last options to consider).
If the college had a website that you could view, you could scan the page for class listings and pull that data in - but more than likely that sort of data will need to be entered manually by you when you ship the app.
If college is having its website and the website provides RSS feed for time table you parse that XML file and show the data which is parse or you can save the time table information of which course in the database and display that using cursors.

Categories

Resources