I need to have a read only database for an android application with three simple tables:
Countries
Cities ( country_id foreign key)
PhoneCountryCodes (country_id foreign key)
I have .csv files that I need to extract data from and fill in these tables. The purpose for these tables is for the android app reading purposes and data validation.
The link here shows how to add data to the managed database Sqlite for android. Yet it seems from the following code that I need a Context to instantiate the DbHelper class:
FeedReaderDbHelper mDbHelper = new FeedReaderDbHelper(getContext());
In other words, I want to add data to the database once and for all (basically Country data, cities and phone country codes), outside of the Activity context.
use getApplicationContext(); If you don't want activity context.
Related
i don't get way to view images according my category my database will be like this
-id
-category : A
-image : URL
I WANT TO SHOW A category in A category activity
You'll need to run a query for that. Firebase has two databases these days and the code you need depends on which one you use.
If you're using the Firebase Realtime Database, the query is:
Query query = FirebaseDatabase.getInstance().getReference("images")
.orderByChild("category").equalTo("A")
After that you need to read the results of this query, as shown in this documentation.
If you're using Cloud Firestore, the query is:
Query query = FirebaseFirestore.getInstance().getCollection("images)
.whereEqualTo("state", "CA");
And then you need to read the results of this query as shown in this documentation.
I have data structure like this for my android app. That can login and only see their profile. I dont make add content or do saving data to the database. So i created the data manually and the users only read and display the data.
How to make login,refer with username = "71140011" and password = "123456" which is inside real time database and the 71140011 only can see their profile only. thanks
final SQLiteDatabase mydb = openOrCreateDatabase("phone_calls",MODE_PRIVATE,null);
mydb.execSQL("CREATE TABLE IF NOT EXISTS Numbers(PhoneNumber VARCHAR,FullName VARCHAR,Cost VARCHAR );");
mydb.execSQL("CREATE TABLE IF NOT EXISTS Calls(FromNum VARCHAR,ToNum VARCHAR,duration VARCHAR );");
Ive created this sqlite in Activity 1. i inserted some data to the first table in first activity.
now i created a second activity and i want to insert data to the other table?what shall i do? create the database again in the second activity and insert in it? or is there any other way?
First of all, you should read the docs - https://developer.android.com/training/basics/data-storage/databases.html
Next, you should try to write simple application in order to use new knowledge.
If it fails, then post the question with more code and Logcat output.
Just create a database helper class which will create all your tables,
then create needed methods like saveObject(YourObject), deleteObject(id),
etc...
Make your helper singleton and initiate it once in Application in onCreate()
and just use it in your activities.
For example you can look here: https://gist.github.com/mikeplate/9173040
Parse : How to save all data from class to Offline Database (SQLite) in android ?
i try to get all data found in specific class and save it in local database to use it when phone without internet connection .
Create a SQLite database table and write method for inserting data into your table after parsing.As simple as that.Refer this for learning SQLite operations
You can use gson for parsing and converting them to objects. To save this data in database, you can use the greendao library for saving and fetching back.
I have an android app which makes remote API calls to fetch some data.
Remote server fetches data from DB table. I have java class which maps to table columns in both Android app and on Server which sends data.
DB TABLE:
Item (
item_id bigint(20)
item_name varchar(20)
price decimal(8,2)
);
//Item class
Class Item {
private long itemId;
private String itemName;
private Float price;
//Corresponding getters/setters
}
STEP1: Remote API convert "Item" Object to JSON and send it to android app
STEP2: Mobile app casts JSON to "Item" class using JSONP
PROBLEM:
Item table on server side is bound to change and over period of time we need to add new columns. Now If I add new columns in server side "STEP2" will break thus app crashes(because of new column). I need to modify apps Item class to accomodate new column so that it won't break. But, If I modify app, app crashed for users who haven't updated app (since they have old item table).
QUESTION:
Suppose, I can send table definition when app starts. What is best way to use this JSON Map to create new Item class out of it?