SQLITE DATABASE for multiple access - android

I would like to ask if any of you out there uses android studio and sqlite for apps that require multiple users to access the database? I have been looking for source codes and examples online, but haven't seen any. I understand that other database might be better but I only have enough time to use sqlite as I am alr using it now. Could anyone help me with example source codes?

viewComment.setText(name+comment);
replace with below code
viewComment.append("\n"+name+comment);
Update -
limit number comments - use counter , after certain number of hits stop appending to text view.
U can make scrollable too.
for above both please check your requirements or UI/UX teams.

You will have to work with RecyclerView here. Add a different layout resource file in your layout folder and bind it to the RecyclerView and all your comments must be stored somewhere, like in a database. You will then achieve your desired structure.

Related

Android, storing big number of small images linked to database

I have been asked to create a tiny android app.
In everyday work i code for .NET and I have no experience connected with Android, but as it is a really small app I guess it's going to be a good experience rather than something hard.
The core of the app would be a small database (probably XML, unless somebody suggest better solution) that would contain categories, names of the institutions assigned with each category and logo (not very high resolution I guess a single file would be <100kB) of the institution.
The database also would not be very big - I expect not more than 1000 records in total. The DB has to be totally offline and local, it cannot require Internet access when operating.
The model I assume would be to ship new version of the application when the database changes (which is not going to be very frequent).
What is the best way to deal with these requirements?
My first idea was to create an XML file that would contain the records and link to the image. The XML and all the images linked to it would be stored in single file (preferably zip) that would be stored in app resources. This is very good as it is going to be very easy to update the database.
The second idea that somebody suggested me would be to use SQLite and store images in BLOB. In general I have read that it isn't a good idea to store images in database directly, and I am afraid if it's going to be possible to meet all requirements mentioned above.
Mostly I have no idea how to update the database easily and attach it to new version of application.
Any suggestions?
I would be grateful for any response.
I wouldn't go about using XML to save your data and by no means zip anything.
I think your way of thinking is ok, but you're making things really complicated for yourself.
Seeing as you're used to .NET I suppose you're also pretty confident with SQL, so I'd suggest you have a look at how to use the built-in SQLite database in Android.
If you would go the XML route you'd have to serialize and de-serialize the XML file over and over again and then parse the XML. Ok you don't have a lot of data, but searching inside an XML file with at least 1000 nodes would be slow in comparison to the performance of a database.
Also upgrading an existing SQLite database is not that hard - Android has methods for that (onUpgrade coming from the SQLiteOpenHelper).
As to saving images I'm assuming that you won't fetch new pictures from the Internet, so it would be best just to store them in the drawable folder of your app (be mindful of different screensizes) and then reading them into an ImageView when needed. To figure out what image should go for what institution I would store either the image name of each image in the SQLite database or store the resource id for each image in the database - for instance R.drawable.myawesomepictureformyinstitution.
I know my answer is somewhat "superficial", but your question is also somewhat "broad" and hard to answer without me actually writing most of the code, and that's not my intention ;-)
Hope this helps - let me know if anything is unclear.

Making a database with android?

I'm working on an android project that requires writing to a created database and later reading from it.
The idea is for the user to fill out a form and then submit, it will submit into a database table in the first row. Then if they hit submit again it will submit to the second row.
I have all of the activity layouts defined but I'm confused on how to make the databases. I'm thinking maybe I can make a content provider?
Can anyone advise me on what to do? All of the questions I look at on here skip the baby steps, and that's what I need
Yes you should make a content provider. There are a lot of great tutorials out there for making databases - try section 8.0 of this one
http://www.vogella.com/articles/AndroidSQLite/article.html
Since you plan to use a pre-loaded (created) database wherein the DB structure has been already defined, Refer to this link on how to include your pre-created DB file into your app :
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
And to then add new data to your database refer to this tut.. You can ignore the create Table part here since you already have the table structure ready.
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
Hope this helps.
First of all you dont need Content provider...Content provider is only need when you want to provide your data to other application...Its kind of central repository of data for other applications.
Now You have to use the SQLITE database in android...Since android support sqlite database..
Below link will guide you...
http://developer.android.com/training/basics/data-storage/databases.html
Google has large manuals for all the aspects of Android development http://developer.android.com/training/basics/data-storage/databases.html
it might be done without content providers too.
this might be helpful.
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

How do the Note Apps create and save a note you wrote

I am working on an app and I basically want to implement some type of function like the note apps do. Basically I have a listview set up that has a link to different xml files. I want the user to have a create new option where they can add some text to an edit text and be able to save the text and add it to the listview I have set up.
My question is how do apps like the Note Pads and Memos ect. do this. Do I need to set up some type of database or?
I have googled it quickly and did a quick search on stack but I don't know if I'm even searching for the right thing. I am just looking for a step in the right direction please!
Thanks!
They all save their data in a database. For android you should use an SQLite database because it is included in the SDK. There are a lot of great tutorials for SQLite out there, but I think that this is the best one
http://www.vogella.com/articles/AndroidSQLite/article.html
It is possible to do this using SharedPrefernces, but I would not recommend it, for efficiency and simplicity

I have some really huge string data to ship with my android app?

I have some really huge data that is required for my android app. I've put it into a sqlite db now. Roughly it is 39k rows and 5 columns. I want this data to be available for my app.
I'm kind of confused as to how I ship my app with it. i can ship the db file with it like discussed in this thread. or I can somehow create XML out of that data and ship it along. But the XML would be really huge. So what is the right way of doing it?
I do not want to download it after user installs the app. That'd be my last option if there are no better clean ways of doing it.
This should help you.
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Basically just ship the database with your apk file.
I think shipping your DB could make some problems with compatibility.
Maybe it will be better to use GZIP'ed SQL code bundled to your .APK?
Or instead of XML for intermediate representation you can use google protobuf, which is most effective data representation format(Also, if you have a lot of strings, you can use it in combination with GZIP).
Check the example here to achieve this functionality.

Android Database

I am new to android. I am creating ToDoTasks application in android. i have crated Gui of the application and it is working perfectly. I am able to add tasks in it. Now i want to know that i want to save 'task list' in an area so that every time user comes on it , than it should maintain the list of previous tasks which were added in it. What is the best way to do this ?
Whether i should go for database in android or is there any other way to do this ?
Please suggest me. Please don't mind , i know this is a silly question but i have no other way to solve it.....
You have multiple options with varying degree of complexity.
Do you foresee sharing your todolist with another application. If yes then you need to host your data as a content provider.But I digress.
The most simplest option is Shared Preferences. The api is very simple to use and you do not need to write a whole lot of plumbing code. You can directly store an list of string in the shared preference of your activity.
The more elaborate solution is using sqllite. If you foresee your domain model to become more complex than just a list of strings, then you should see if the additional complexity is worth it.
Look here for more details. (I will not worry about the file options, the other two mentioned here are superior to that solution)
You can use sqlLite db for android. See this or this for example.
Here is another example of an SQLite implementation:
http://p-xr.com/android-tutorial-simple-but-persistent-data-storage/

Categories

Resources