Multiple retrievable instances of an activity in Android Studio - java

I have an app, which takes input from a user (name, phone#, email) and generates a QR code. I used shared preferences to save the data so that the user does not have to fill out the fields every time. Right now, this only works for one person, and I want to add functionality for a second or third person.
Essentially, a main menu, that can open as many instances of the QR Generator as needed, and retrieve already open instances so that you can access the QR Codes of each person when you need it.
I have no idea where to start, so any help would be much appreciated. If you need to see the current code for the QR generator, I can attach that.

You should store the data in a database instead of sharedpreferences. And it should work smoothly. Database can store a lot of data and that too for multiple people. Which might help. You can store all the data of one person in one single row creating multiple columns for multiple attributes such as name, phone, email.
You can create multiple rows, and hence multiple people can store their data.
Database can used in two ways in android
Room persistence (also uses sqlite)
https://developer.android.com/training/data-storage/room
Raw SQLite database
https://developer.android.com/training/data-storage/sqlite

Related

JavaFX, student registration style system without database

I've been creating a small sample project to display my learnings in JavaFX, and it's completed as far as functionality. My problem now is that The lead instructor has asked me to show a database style relation between the student page and the faculty page, showing that a student has tried to add a course. I've got one page for the student where they can select a course from a table. I then have a faculty page that displays a current schedule table, and a tab on the pane that allows the faculty to add or delete a class. I'm wondering the best way without a database to show the s student has selected a course from the table which they choose to register for. I'm Using TableView for all tables, creating observable lists where I can add items and everything displays perfectly on the tables. I have the add and delete functions working perfectly well also. I only need to find a way to transfer the selection from the student to be viewable by the faculty, perhaps in a text file or something like that. Any suggestion or help is much appreciated.
There are indeed several ways. One you have suggested yourself.
You could write the data to a text file using the PrintWriter class (java.io.PrintWriter). You can recall the data by using the Scanner class.
If there is no need for the data to be stored after closing your program, the textile will be redundant. It would be better practice to store the data in an object/instance which can be aggregated by the faculty.
For a more specific answer, be more specific in your question.

Store some data on server to access without a db

I want to store a little bit of data on my server that can be accessed easily by anyone. It's for a game I am making and I want to store a few things such as:
Game version (String)
Description (Long String)
News (Array of Strings)
Changelog (Array of Strings)
etc...
I figured that making a whole database and table for this would be overkill. I would like to be able to access the information using various types of media but I at least ant it to work with PHP (web) and Java (Desktop and android). Also the data will be updated and inputted manually by only me but readable publicly so that other websites can use it if they choose. What would I use for this kind of thing?
Extra: I might eventually want to input data manually. Things such as "Players Joined" would be managed by my server and would increment it automatically.So if it can do that too that would be great.
I have decided to use a Database and access the data with MySQL. I already have one for my game so it is a good choice because of that (this means I won't be creating a whole database just for this). I will create a table that will store this data and the table will only have 1 row (ID = 0). I will access it by selecting the row with ID = 0. I will have to create other tables with news and changelogs too.
If you have a similar question to mine, check this out:
http://www.dummies.com/how-to/content/storing-data-with-php-flat-file-or-database.html
It provided some useful advice. Also look into JSON or XML and SQLite.
You might want to check out H2 database. It can run as an embedded database (just include a jar, no extra installation, etc.), is very solid and you can get up and running very quickly.

Mysql Db Layout for Movie Information from java

I'm trying to write a java-based movie database program. It recursively searches a given list of folders, retrieves information about the movie files within, and allows you to search for movies using tags/actors/file resolution/etc, and will show a cover thumbnail of the movie and screenshots.
The program as I have it now stores information (atm only filename/size) in arraylists, and generates a html page with the thumbnails. I would like to use a mysql database instead so it will persistently store the movie information and doesn't have to search through all the folders every time.
I can use a "Media" object for each movie to store all this info, but I'm not sure of the best way to store this in a database. I don't want to just serialize the Media objects because then I would have to iterate through the whole db to search, which would be slow. I assume I need to use mysql queries to search.
I have only a less than basic knowledge of database design although I do have an idea how to use jdbc to create/access a mysql database once I have decided on a layout.
Can anyone give me some pointers on what I need to learn and where to learn it in order to decide how to lay out/index and link the tables for my movie database?
Here's my current Media object:
public class Media {
File file_location;
String filename;
Date date;
int hres;
int vres;
boolean has_tbn;
File tbnloc;
boolean has_ss;
File ssloc;
int length;
String[] actors;
String[] tags;
boolean HD;
long filesize;
String md5;
From what you said, I assume you already know how to setup/create a MySQL database, so I won't bother with that.
First, you will need to make a table for your media. Start designing a column that can store each object in your Media class with the appropriate data type, as well as set a primary key, which should be unique. This is preferably a separate id number. Also be sure to specify which columns cannot be null or blank, to avoid accidentally writing incomplete data.
However, I also see you have arrays for actors and tags. As a designer, I would prefer for these to be in separate tables, with another table joining them to the main media table for a many-to-many relationship. You could also make it simpler and just set it as a long string with a separator that you will parse and place into the array.
You may want to reconsider saving a file directly into MySQL as well. I prefer just saving the file location and keeping the actual file as is.
I think you should also take a look at the sample database the current version of MySQL has, called Sakila, which should also be available for install when you install the latest version of MySQL. It's a database for a video store, and thus has well-designed tables for storing film data and all its related factors.

Android arraylist large number of string objects

I am developing a Android application for a website. It has large number of users around 100000. I have to fetch these users to an Arraylist for a custom user search. Is that a good practice to store this much amount of data in an Arraylist (particularly in Android). If not I am planning to use a Sqlite database any suggestions?
You do not want to use a list of any type.
Databases are optimized to store and search through large amounts of data, if you store these usernames in an ArrayList, you would be responsible for ensuring that you efficiently search.
This seems like a poor idea in the first place. Why would you want to have a local copy of all 1lakh+ usernames? This is terrible waste of bandwidth! It would be better if the application could query the database for the usernames it is searching for. You could then store the results only on the client.
ex: SELECT * FROM `user` WHERE `name` LIKE "david"
Store only the results from the query. Not every user.
Make Data Classes and make it Serializable and use file storage.. Because if your using DataBase getting and putting data is a different task... storing file Object is better for data handling..
It seems that it is not a good idea to store the content in an ArrayList. Depending upon the data or your application, you may get a 'OutOfMemory' error. Try persisting the information to a SQLite database or file.
On the other hand, I do not find the necessity to bulk download the 1 lakh user data and store it locally for search on device. You could make your service to do the search and return only the search results. If this is possible, then storing it in ArrayList is not bad. If the size of your arraylist exceeds the amount tolerated by the DVM, you could override onLowMemory callback and empty the list contents. By this way you could prevent your app from being killed

Android | SQLLite : Pre-created database updating without using SQLiteOpenHelper

My app uses a SQLite database for the information. I have a function that checks to see if the folder and database are already present, if they aren't it will go on the internet ( currently I am using dropbox to store the db file ) and download the database and store it on the sd card, then I it will open the database. The database is writable as it lets the user rate an object. I have two questions.
1.) I would love to provide updates to the database and then have my app update the database if the version number is higher and replace the existing one. I have done some research and from what I have found it is possible to store an xml or json file with the version number of and the just parse the information and if the version number is higher download the new database.
Can someone provide an example of how this is accomplished and whether it is better to use xml or json for this task?
2.) Is there a way to save the rating in the new version of the database when the new is downloaded and accessed?
Thanks
two nights ago I wrote something like that.
pack your database structure as an array in a webservice method by reading field names and field types. the structure of array is arbitrary.
call web service method and you must receive a string that represent a JSONArray object, if you sent it as json with json_encode() method in php.
read structure and make CREATE DB query string with for loops.
execute query, so you must have database.
also you can send alot of information with arrays.
introducing each part is hard, so for each part google it.
don't forget to convert field types to match SQLite types such as VARCHAR=>TEXT, smallint=>INTEGER , ...

Categories

Resources