Content Provider – Part 1 – Contract class

Content Provider – Part 1 – Contract class

A Content Provider(CP) is a component that encapsulates data, expose them through a standard API and optionally make these data available to other applications. CP is independent of a data storage, which can be local, remote or mixed. Contract class We need a CP contract class to describe the data exposed from the CP(tables, columns, SQL creation strings, etc). The table information is in nested classes, a separate class for each table. Those classes should describe how to access the table, the table’s URI and the column name. The table…

Content Provider – Part 1 – Contract class Read More

Android – SQLite and SQLiteOpenHelper class

Android – SQLite and SQLiteOpenHelper class

SQLite provides a structured data storage and it is lightweight and run-in process, which means the library runs as part of the application. There is no need for server installation and configuration. SQLite has 5 datatypes: TEXT NUMERIC INTEGER REAL BLOB You can read more here. SQLiteOpenHelper class SQLiteOpenHelper class provides methods to access, manage the creation and version management of the database. To create an SQLiteOpenHelper class, create a new Java class file. The class should extend the SQLiteOpenHelper class. Press Alt + Enter and select Implement Methods. Click…

Android – SQLite and SQLiteOpenHelper class Read More

Android – Create a DB contract class

Android – Create a DB contract class

A Database contract class is a class that holds information about the database, schema/structure. It also has constants that describes the database, tables, columns and table creation strings. One more thing to remember is that we do not need instantiate it, because it holds only information. Let’s start. Create a new Java class file. The class must be final. The constructor should be private and empty. Now create a public, static and final class for each table in the database that implements Basecolums if you want to use an ID…

Android – Create a DB contract class Read More

Java – class inheritance | superclass and subclass

Java – class inheritance | superclass and subclass

In Java a class can inherit another class. The inherited class is called Superclass and the class that inherits another class it is called subclass. syntax: puplic class subclassName extends superclassName{ additional fields and methods or method overriding } The subclass should only declare new fields, implement new methods or override superclass methods. All the variables and methods of the superclass are inherited automatically. As you see on the example above, the subclass’s constructor called the superclass constructor using the super keyword. This is important. The subclass must initialize the…

Java – class inheritance | superclass and subclass Read More

Java – Random class

Java – Random class

Random class generates pseudo-random numbers, not really random numbers but they appear to be. use: import java.util.Random;…Random rand = new Random();int randomNumber = rand.nextInt(); common methods: nextInt() – Returns the next pseudorandom, uniformly distributed int value from this random number generator’s sequence. nextInt(max) – Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator’s sequence. nextDouble() – Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator’s sequence. Read more here. Random Number Within a Given Range Random letter Random rand =…

Java – Random class Read More