kandi background
Explore Kits

volley | Sample android app using Volley library | Learning library

 by   adamrocker Java Version: Current License: No License

 by   adamrocker Java Version: Current License: No License

Download this library from

kandi X-RAY | volley Summary

volley is a Java library typically used in Tutorial, Learning applications. volley has no bugs, it has no vulnerabilities and it has low support. However volley build file is not available. You can download it from GitHub.
Sample android app using Volley library.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • volley has a low active ecosystem.
  • It has 162 star(s) with 133 fork(s). There are 21 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 1 open issues and 0 have been closed. On average issues are closed in 1714 days. There are 1 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of volley is current.
volley Support
Best in #Learning
Average in #Learning
volley Support
Best in #Learning
Average in #Learning

quality kandi Quality

  • volley has 0 bugs and 0 code smells.
volley Quality
Best in #Learning
Average in #Learning
volley Quality
Best in #Learning
Average in #Learning

securitySecurity

  • volley has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • volley code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
volley Security
Best in #Learning
Average in #Learning
volley Security
Best in #Learning
Average in #Learning

license License

  • volley does not have a standard license declared.
  • Check the repository for any license declaration and review the terms closely.
  • Without a license, all rights are reserved, and you cannot use the library in your applications.
volley License
Best in #Learning
Average in #Learning
volley License
Best in #Learning
Average in #Learning

buildReuse

  • volley releases are not available. You will need to build from source code and install.
  • volley has no build file. You will be need to create the build yourself to build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
volley Reuse
Best in #Learning
Average in #Learning
volley Reuse
Best in #Learning
Average in #Learning
Top functions reviewed by kandi - BETA

kandi has reviewed volley and discovered the below as its top functions. This is intended to give you an instant insight into volley implemented functionality, and help decide if they suit your requirements.

  • Calculate the exact format .
    • Build the drop down list .
      • Installs the decor .
        • This method is called to update the view .
          • Parse the menu .
            • Determines the position of the item in the adapter .
              • Creates an ActionBarSherlock for the given activity .
                • Returns the float value of this keyframe .
                  • Returns the integer value of this keyframe .
                    • Load the logo from the manifest .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      volley Key Features

                      Sample android app using Volley library.

                      volley Examples and Code Snippets

                      See all related Code Snippets

                      default

                      copy iconCopydownload iconDownload
                      1. git clone this project
                      2. Import actionbarsherlock into your eclipse as an existing Android project
                      3. Clean build the actionbarsherlock project on eclipse
                      4. Import VolleySample into your eclipse as an existing Android project
                      5. Clean build the VolleySample project on eclipse
                      6. Make sure the actionbarsherlock libray project is refered from VolleySample project
                      
                      What's Volley

                      Project update recommended: Android Gradle Plugin can be upgraded. Error message: Can not find AGP version in build files

                      copy iconCopydownload iconDownload
                      repositories {
                          jcenter()
                      }
                      
                      repositories {
                          mavenCentral()
                      }
                      
                      repositories {
                          jcenter()
                      }
                      
                      repositories {
                          mavenCentral()
                      }
                      
                      cd to project directory
                      bash ./gradlew help --scan
                      bash ./gradlew wrapper --gradle-version 7.0.2
                      

                      How can I store data with nested object data in Android? [Room]

                      copy iconCopydownload iconDownload
                      class MyData {
                          public static final String TABLE_NAME = "_mydata";
                          public static final String COLUMN_FOOD_ID = "_food_id";
                          public static final String COLUMN_FOOD_NAME = "_food_name";
                          long food_id;
                          String food_name;
                          Unit[] units;
                      
                          public MyData(long food_id, String food_name, Unit[] units) {
                              this.food_id = food_id;
                              this.food_name = food_name;
                              this.units = units;
                          }
                      }
                      
                      class Unit {
                          public static final String TABLE_NAME = "_unit";
                          public static final String COLUMN_UNIT = "_unit";
                          public static final String COLUMN_AMOUNT = "_amount";
                          public static final String COLUMN_CALORY = "_calory";
                          public static final String COLUMN_FOOD_ID_PARENT ="parent_food_id";
                          String unit;
                          double amount;
                          double calory;
                      
                          public Unit(String unit, double amount, double calory) {
                              this.unit = unit;
                              this.amount = amount;
                              this.calory = calory;
                          }
                      }
                      
                      class DatabaseHelper extends SQLiteOpenHelper {
                      
                          public static final String DATABASE_NAME = "my_database.db";
                          public static final int DATABASE_VERSION = 1;
                      
                          private SQLiteDatabase db;
                          private static volatile DatabaseHelper instance = null;
                          private DatabaseHelper(Context context) {
                              super(context,DATABASE_NAME,null,DATABASE_VERSION);
                              db = this.getWritableDatabase();
                          }
                      
                          /* Use a singleton approach */
                          public static DatabaseHelper getInstance(Context context) {
                              if (instance == null) {
                                  instance = new DatabaseHelper(context);
                              }
                              return instance;
                          }
                      
                          @Override
                          public void onCreate(SQLiteDatabase db) {
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + MyData.TABLE_NAME + "(" +
                                              MyData.COLUMN_FOOD_ID + " INTEGER PRIMARY KEY," +
                                              MyData.COLUMN_FOOD_NAME + " TEXT" +
                                              ")"
                              );
                      
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + Unit.TABLE_NAME + "(" +
                                              Unit.COLUMN_UNIT + " TEXT," +
                                              Unit.COLUMN_AMOUNT + " REAL," +
                                              Unit.COLUMN_CALORY + " REAL," +
                                              Unit.COLUMN_FOOD_ID_PARENT +
                                              /* Foreign Key Constraint to enforce referential integrity*/
                                              " INTEGER REFERENCES " + MyData.TABLE_NAME + "(" + MyData.COLUMN_FOOD_ID + ") " +
                                              /* These make maintaining referential integrity easier */
                                              "ON DELETE CASCADE " +
                                              "ON UPDATE CASCADE, " +
                                              /* define the primary key */
                                              " PRIMARY KEY(" +
                                              Unit.COLUMN_UNIT + "," + Unit.COLUMN_AMOUNT + "," + Unit.COLUMN_CALORY +
                                              ")" +
                                              ")"
                              );
                      
                          }
                      
                          @Override
                          public void onUpgrade(SQLiteDatabase db, int i, int i1) {
                              /* not expecting to increase the database version so leave this to do nothing */
                          }
                      
                          public long insertMyData(MyData myData) {
                              ContentValues cv = new ContentValues();
                              cv.put(MyData.COLUMN_FOOD_ID,myData.food_id);
                              cv.put(MyData.COLUMN_FOOD_NAME,myData.food_name);
                              return db.insert(MyData.TABLE_NAME,null,cv);
                          }
                      
                          public long insertUnit(Unit unit, long parentId) {
                              ContentValues cv = new ContentValues();
                              cv.put(Unit.COLUMN_UNIT,unit.unit);
                              cv.put(Unit.COLUMN_AMOUNT,unit.amount);
                              cv.put(Unit.COLUMN_CALORY,unit.calory);
                              cv.put(Unit.COLUMN_FOOD_ID_PARENT,parentId);
                              return db.insert(Unit.TABLE_NAME,null,cv);
                          }
                      
                          public void massInsert(String jsonString) {
                              MyData[] extracted = new Gson().fromJson(jsonString,MyData[].class);
                              db.beginTransaction();
                              for(MyData m: new Gson().fromJson(jsonString,MyData[].class)) {
                                  long food_id = insertMyData(m);
                                  if (food_id > 0) {
                                      for(Unit u: m.units) {
                                          insertUnit(u,food_id);
                                      }
                                  }
                              }
                              db.setTransactionSuccessful();
                              db.endTransaction();
                          }
                      }
                      
                      public class MainActivity extends AppCompatActivity {
                      
                          MyData[] TESTDATA = {
                                  new MyData(
                                          1,
                                          "Bat",
                                          new Unit[]{
                                                  new Unit("Unit A",15.0000,32.4877372383),
                                                  new Unit("Unit C",110.0000,238.243404414),
                                                  new Unit("Unit F",1.0000,2.16584914922)
                                          }
                                          ),
                                  new MyData(
                                          2,
                                          "Another",
                                          new Unit[]{
                                                  new Unit("Unit A",17.0000,3.4877372383),
                                                  new Unit("Unit C",10.0000,382.243404414),
                                                  new Unit("Unit F",3.0000,5.16584914922)
                                          }
                                  ),
                          };
                      
                          DatabaseHelper dbHelper;
                      
                          @Override
                          protected void onCreate(Bundle savedInstanceState) {
                              super.onCreate(savedInstanceState);
                              setContentView(R.layout.activity_main);
                      
                              String test = new Gson().toJson(TESTDATA);
                              Log.d("APPINFO","TESTDATA as JSON is\n\t" + test);
                              //MyData[] extracted = new Gson().fromJson(test,MyData[].class);
                      
                              dbHelper = DatabaseHelper.getInstance(this); // Prepare to use the database
                              dbHelper.massInsert(test); // Actually use the database to insert the data
                      
                              /* Example of extracting data using a JOIN to combine the MyData and the related Units */
                              Cursor csr =  dbHelper.getWritableDatabase().query(
                                      MyData.TABLE_NAME + " JOIN " + Unit.TABLE_NAME + " ON " + Unit.COLUMN_FOOD_ID_PARENT + "=" + MyData.COLUMN_FOOD_ID,
                                      null,null,null,null,null,null
                                      );
                              DatabaseUtils.dumpCursor(csr);
                              csr.close();
                      
                          }
                      }
                      
                      2022-01-08 07:32:14.666  D/APPINFO: TESTDATA as JSON is
                              [{"food_id":1,"food_name":"Bat","units":[{"amount":15.0,"calory":32.4877372383,"unit":"Unit A"},{"amount":110.0,"calory":238.243404414,"unit":"Unit C"},{"amount":1.0,"calory":2.16584914922,"unit":"Unit F"}]},{"food_id":2,"food_name":"Another","units":[{"amount":17.0,"calory":3.4877372383,"unit":"Unit A"},{"amount":10.0,"calory":382.243404414,"unit":"Unit C"},{"amount":3.0,"calory":5.16584914922,"unit":"Unit F"}]}]
                      
                      2022-01-08 07:32:14.698  I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@f302fce
                      2022-01-08 07:32:14.699  I/System.out: 0 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.699  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.699  I/System.out:    _amount=15
                      2022-01-08 07:32:14.699  I/System.out:    _calory=32.4877
                      2022-01-08 07:32:14.699  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.699  I/System.out: }
                      2022-01-08 07:32:14.699  I/System.out: 1 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.700  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.701  I/System.out:    _amount=110
                      2022-01-08 07:32:14.701  I/System.out:    _calory=238.243
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.701  I/System.out: 2 {
                      2022-01-08 07:32:14.701  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.701  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.701  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.701  I/System.out:    _amount=1
                      2022-01-08 07:32:14.701  I/System.out:    _calory=2.16585
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 3 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.702  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.702  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.702  I/System.out:    _amount=17
                      2022-01-08 07:32:14.702  I/System.out:    _calory=3.48774
                      2022-01-08 07:32:14.702  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.702  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 4 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.703  I/System.out:    _amount=10
                      2022-01-08 07:32:14.703  I/System.out:    _calory=382.243
                      2022-01-08 07:32:14.703  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.703  I/System.out: }
                      2022-01-08 07:32:14.703  I/System.out: 5 {
                      2022-01-08 07:32:14.703  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.703  I/System.out:    _amount=3
                      2022-01-08 07:32:14.704  I/System.out:    _calory=5.16585
                      2022-01-08 07:32:14.704  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.704  I/System.out: }
                      2022-01-08 07:32:14.704  I/System.out: <<<<<
                      
                      class MyData {
                          public static final String TABLE_NAME = "_mydata";
                          public static final String COLUMN_FOOD_ID = "_food_id";
                          public static final String COLUMN_FOOD_NAME = "_food_name";
                          long food_id;
                          String food_name;
                          Unit[] units;
                      
                          public MyData(long food_id, String food_name, Unit[] units) {
                              this.food_id = food_id;
                              this.food_name = food_name;
                              this.units = units;
                          }
                      }
                      
                      class Unit {
                          public static final String TABLE_NAME = "_unit";
                          public static final String COLUMN_UNIT = "_unit";
                          public static final String COLUMN_AMOUNT = "_amount";
                          public static final String COLUMN_CALORY = "_calory";
                          public static final String COLUMN_FOOD_ID_PARENT ="parent_food_id";
                          String unit;
                          double amount;
                          double calory;
                      
                          public Unit(String unit, double amount, double calory) {
                              this.unit = unit;
                              this.amount = amount;
                              this.calory = calory;
                          }
                      }
                      
                      class DatabaseHelper extends SQLiteOpenHelper {
                      
                          public static final String DATABASE_NAME = "my_database.db";
                          public static final int DATABASE_VERSION = 1;
                      
                          private SQLiteDatabase db;
                          private static volatile DatabaseHelper instance = null;
                          private DatabaseHelper(Context context) {
                              super(context,DATABASE_NAME,null,DATABASE_VERSION);
                              db = this.getWritableDatabase();
                          }
                      
                          /* Use a singleton approach */
                          public static DatabaseHelper getInstance(Context context) {
                              if (instance == null) {
                                  instance = new DatabaseHelper(context);
                              }
                              return instance;
                          }
                      
                          @Override
                          public void onCreate(SQLiteDatabase db) {
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + MyData.TABLE_NAME + "(" +
                                              MyData.COLUMN_FOOD_ID + " INTEGER PRIMARY KEY," +
                                              MyData.COLUMN_FOOD_NAME + " TEXT" +
                                              ")"
                              );
                      
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + Unit.TABLE_NAME + "(" +
                                              Unit.COLUMN_UNIT + " TEXT," +
                                              Unit.COLUMN_AMOUNT + " REAL," +
                                              Unit.COLUMN_CALORY + " REAL," +
                                              Unit.COLUMN_FOOD_ID_PARENT +
                                              /* Foreign Key Constraint to enforce referential integrity*/
                                              " INTEGER REFERENCES " + MyData.TABLE_NAME + "(" + MyData.COLUMN_FOOD_ID + ") " +
                                              /* These make maintaining referential integrity easier */
                                              "ON DELETE CASCADE " +
                                              "ON UPDATE CASCADE, " +
                                              /* define the primary key */
                                              " PRIMARY KEY(" +
                                              Unit.COLUMN_UNIT + "," + Unit.COLUMN_AMOUNT + "," + Unit.COLUMN_CALORY +
                                              ")" +
                                              ")"
                              );
                      
                          }
                      
                          @Override
                          public void onUpgrade(SQLiteDatabase db, int i, int i1) {
                              /* not expecting to increase the database version so leave this to do nothing */
                          }
                      
                          public long insertMyData(MyData myData) {
                              ContentValues cv = new ContentValues();
                              cv.put(MyData.COLUMN_FOOD_ID,myData.food_id);
                              cv.put(MyData.COLUMN_FOOD_NAME,myData.food_name);
                              return db.insert(MyData.TABLE_NAME,null,cv);
                          }
                      
                          public long insertUnit(Unit unit, long parentId) {
                              ContentValues cv = new ContentValues();
                              cv.put(Unit.COLUMN_UNIT,unit.unit);
                              cv.put(Unit.COLUMN_AMOUNT,unit.amount);
                              cv.put(Unit.COLUMN_CALORY,unit.calory);
                              cv.put(Unit.COLUMN_FOOD_ID_PARENT,parentId);
                              return db.insert(Unit.TABLE_NAME,null,cv);
                          }
                      
                          public void massInsert(String jsonString) {
                              MyData[] extracted = new Gson().fromJson(jsonString,MyData[].class);
                              db.beginTransaction();
                              for(MyData m: new Gson().fromJson(jsonString,MyData[].class)) {
                                  long food_id = insertMyData(m);
                                  if (food_id > 0) {
                                      for(Unit u: m.units) {
                                          insertUnit(u,food_id);
                                      }
                                  }
                              }
                              db.setTransactionSuccessful();
                              db.endTransaction();
                          }
                      }
                      
                      public class MainActivity extends AppCompatActivity {
                      
                          MyData[] TESTDATA = {
                                  new MyData(
                                          1,
                                          "Bat",
                                          new Unit[]{
                                                  new Unit("Unit A",15.0000,32.4877372383),
                                                  new Unit("Unit C",110.0000,238.243404414),
                                                  new Unit("Unit F",1.0000,2.16584914922)
                                          }
                                          ),
                                  new MyData(
                                          2,
                                          "Another",
                                          new Unit[]{
                                                  new Unit("Unit A",17.0000,3.4877372383),
                                                  new Unit("Unit C",10.0000,382.243404414),
                                                  new Unit("Unit F",3.0000,5.16584914922)
                                          }
                                  ),
                          };
                      
                          DatabaseHelper dbHelper;
                      
                          @Override
                          protected void onCreate(Bundle savedInstanceState) {
                              super.onCreate(savedInstanceState);
                              setContentView(R.layout.activity_main);
                      
                              String test = new Gson().toJson(TESTDATA);
                              Log.d("APPINFO","TESTDATA as JSON is\n\t" + test);
                              //MyData[] extracted = new Gson().fromJson(test,MyData[].class);
                      
                              dbHelper = DatabaseHelper.getInstance(this); // Prepare to use the database
                              dbHelper.massInsert(test); // Actually use the database to insert the data
                      
                              /* Example of extracting data using a JOIN to combine the MyData and the related Units */
                              Cursor csr =  dbHelper.getWritableDatabase().query(
                                      MyData.TABLE_NAME + " JOIN " + Unit.TABLE_NAME + " ON " + Unit.COLUMN_FOOD_ID_PARENT + "=" + MyData.COLUMN_FOOD_ID,
                                      null,null,null,null,null,null
                                      );
                              DatabaseUtils.dumpCursor(csr);
                              csr.close();
                      
                          }
                      }
                      
                      2022-01-08 07:32:14.666  D/APPINFO: TESTDATA as JSON is
                              [{"food_id":1,"food_name":"Bat","units":[{"amount":15.0,"calory":32.4877372383,"unit":"Unit A"},{"amount":110.0,"calory":238.243404414,"unit":"Unit C"},{"amount":1.0,"calory":2.16584914922,"unit":"Unit F"}]},{"food_id":2,"food_name":"Another","units":[{"amount":17.0,"calory":3.4877372383,"unit":"Unit A"},{"amount":10.0,"calory":382.243404414,"unit":"Unit C"},{"amount":3.0,"calory":5.16584914922,"unit":"Unit F"}]}]
                      
                      2022-01-08 07:32:14.698  I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@f302fce
                      2022-01-08 07:32:14.699  I/System.out: 0 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.699  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.699  I/System.out:    _amount=15
                      2022-01-08 07:32:14.699  I/System.out:    _calory=32.4877
                      2022-01-08 07:32:14.699  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.699  I/System.out: }
                      2022-01-08 07:32:14.699  I/System.out: 1 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.700  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.701  I/System.out:    _amount=110
                      2022-01-08 07:32:14.701  I/System.out:    _calory=238.243
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.701  I/System.out: 2 {
                      2022-01-08 07:32:14.701  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.701  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.701  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.701  I/System.out:    _amount=1
                      2022-01-08 07:32:14.701  I/System.out:    _calory=2.16585
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 3 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.702  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.702  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.702  I/System.out:    _amount=17
                      2022-01-08 07:32:14.702  I/System.out:    _calory=3.48774
                      2022-01-08 07:32:14.702  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.702  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 4 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.703  I/System.out:    _amount=10
                      2022-01-08 07:32:14.703  I/System.out:    _calory=382.243
                      2022-01-08 07:32:14.703  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.703  I/System.out: }
                      2022-01-08 07:32:14.703  I/System.out: 5 {
                      2022-01-08 07:32:14.703  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.703  I/System.out:    _amount=3
                      2022-01-08 07:32:14.704  I/System.out:    _calory=5.16585
                      2022-01-08 07:32:14.704  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.704  I/System.out: }
                      2022-01-08 07:32:14.704  I/System.out: <<<<<
                      
                      class MyData {
                          public static final String TABLE_NAME = "_mydata";
                          public static final String COLUMN_FOOD_ID = "_food_id";
                          public static final String COLUMN_FOOD_NAME = "_food_name";
                          long food_id;
                          String food_name;
                          Unit[] units;
                      
                          public MyData(long food_id, String food_name, Unit[] units) {
                              this.food_id = food_id;
                              this.food_name = food_name;
                              this.units = units;
                          }
                      }
                      
                      class Unit {
                          public static final String TABLE_NAME = "_unit";
                          public static final String COLUMN_UNIT = "_unit";
                          public static final String COLUMN_AMOUNT = "_amount";
                          public static final String COLUMN_CALORY = "_calory";
                          public static final String COLUMN_FOOD_ID_PARENT ="parent_food_id";
                          String unit;
                          double amount;
                          double calory;
                      
                          public Unit(String unit, double amount, double calory) {
                              this.unit = unit;
                              this.amount = amount;
                              this.calory = calory;
                          }
                      }
                      
                      class DatabaseHelper extends SQLiteOpenHelper {
                      
                          public static final String DATABASE_NAME = "my_database.db";
                          public static final int DATABASE_VERSION = 1;
                      
                          private SQLiteDatabase db;
                          private static volatile DatabaseHelper instance = null;
                          private DatabaseHelper(Context context) {
                              super(context,DATABASE_NAME,null,DATABASE_VERSION);
                              db = this.getWritableDatabase();
                          }
                      
                          /* Use a singleton approach */
                          public static DatabaseHelper getInstance(Context context) {
                              if (instance == null) {
                                  instance = new DatabaseHelper(context);
                              }
                              return instance;
                          }
                      
                          @Override
                          public void onCreate(SQLiteDatabase db) {
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + MyData.TABLE_NAME + "(" +
                                              MyData.COLUMN_FOOD_ID + " INTEGER PRIMARY KEY," +
                                              MyData.COLUMN_FOOD_NAME + " TEXT" +
                                              ")"
                              );
                      
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + Unit.TABLE_NAME + "(" +
                                              Unit.COLUMN_UNIT + " TEXT," +
                                              Unit.COLUMN_AMOUNT + " REAL," +
                                              Unit.COLUMN_CALORY + " REAL," +
                                              Unit.COLUMN_FOOD_ID_PARENT +
                                              /* Foreign Key Constraint to enforce referential integrity*/
                                              " INTEGER REFERENCES " + MyData.TABLE_NAME + "(" + MyData.COLUMN_FOOD_ID + ") " +
                                              /* These make maintaining referential integrity easier */
                                              "ON DELETE CASCADE " +
                                              "ON UPDATE CASCADE, " +
                                              /* define the primary key */
                                              " PRIMARY KEY(" +
                                              Unit.COLUMN_UNIT + "," + Unit.COLUMN_AMOUNT + "," + Unit.COLUMN_CALORY +
                                              ")" +
                                              ")"
                              );
                      
                          }
                      
                          @Override
                          public void onUpgrade(SQLiteDatabase db, int i, int i1) {
                              /* not expecting to increase the database version so leave this to do nothing */
                          }
                      
                          public long insertMyData(MyData myData) {
                              ContentValues cv = new ContentValues();
                              cv.put(MyData.COLUMN_FOOD_ID,myData.food_id);
                              cv.put(MyData.COLUMN_FOOD_NAME,myData.food_name);
                              return db.insert(MyData.TABLE_NAME,null,cv);
                          }
                      
                          public long insertUnit(Unit unit, long parentId) {
                              ContentValues cv = new ContentValues();
                              cv.put(Unit.COLUMN_UNIT,unit.unit);
                              cv.put(Unit.COLUMN_AMOUNT,unit.amount);
                              cv.put(Unit.COLUMN_CALORY,unit.calory);
                              cv.put(Unit.COLUMN_FOOD_ID_PARENT,parentId);
                              return db.insert(Unit.TABLE_NAME,null,cv);
                          }
                      
                          public void massInsert(String jsonString) {
                              MyData[] extracted = new Gson().fromJson(jsonString,MyData[].class);
                              db.beginTransaction();
                              for(MyData m: new Gson().fromJson(jsonString,MyData[].class)) {
                                  long food_id = insertMyData(m);
                                  if (food_id > 0) {
                                      for(Unit u: m.units) {
                                          insertUnit(u,food_id);
                                      }
                                  }
                              }
                              db.setTransactionSuccessful();
                              db.endTransaction();
                          }
                      }
                      
                      public class MainActivity extends AppCompatActivity {
                      
                          MyData[] TESTDATA = {
                                  new MyData(
                                          1,
                                          "Bat",
                                          new Unit[]{
                                                  new Unit("Unit A",15.0000,32.4877372383),
                                                  new Unit("Unit C",110.0000,238.243404414),
                                                  new Unit("Unit F",1.0000,2.16584914922)
                                          }
                                          ),
                                  new MyData(
                                          2,
                                          "Another",
                                          new Unit[]{
                                                  new Unit("Unit A",17.0000,3.4877372383),
                                                  new Unit("Unit C",10.0000,382.243404414),
                                                  new Unit("Unit F",3.0000,5.16584914922)
                                          }
                                  ),
                          };
                      
                          DatabaseHelper dbHelper;
                      
                          @Override
                          protected void onCreate(Bundle savedInstanceState) {
                              super.onCreate(savedInstanceState);
                              setContentView(R.layout.activity_main);
                      
                              String test = new Gson().toJson(TESTDATA);
                              Log.d("APPINFO","TESTDATA as JSON is\n\t" + test);
                              //MyData[] extracted = new Gson().fromJson(test,MyData[].class);
                      
                              dbHelper = DatabaseHelper.getInstance(this); // Prepare to use the database
                              dbHelper.massInsert(test); // Actually use the database to insert the data
                      
                              /* Example of extracting data using a JOIN to combine the MyData and the related Units */
                              Cursor csr =  dbHelper.getWritableDatabase().query(
                                      MyData.TABLE_NAME + " JOIN " + Unit.TABLE_NAME + " ON " + Unit.COLUMN_FOOD_ID_PARENT + "=" + MyData.COLUMN_FOOD_ID,
                                      null,null,null,null,null,null
                                      );
                              DatabaseUtils.dumpCursor(csr);
                              csr.close();
                      
                          }
                      }
                      
                      2022-01-08 07:32:14.666  D/APPINFO: TESTDATA as JSON is
                              [{"food_id":1,"food_name":"Bat","units":[{"amount":15.0,"calory":32.4877372383,"unit":"Unit A"},{"amount":110.0,"calory":238.243404414,"unit":"Unit C"},{"amount":1.0,"calory":2.16584914922,"unit":"Unit F"}]},{"food_id":2,"food_name":"Another","units":[{"amount":17.0,"calory":3.4877372383,"unit":"Unit A"},{"amount":10.0,"calory":382.243404414,"unit":"Unit C"},{"amount":3.0,"calory":5.16584914922,"unit":"Unit F"}]}]
                      
                      2022-01-08 07:32:14.698  I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@f302fce
                      2022-01-08 07:32:14.699  I/System.out: 0 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.699  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.699  I/System.out:    _amount=15
                      2022-01-08 07:32:14.699  I/System.out:    _calory=32.4877
                      2022-01-08 07:32:14.699  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.699  I/System.out: }
                      2022-01-08 07:32:14.699  I/System.out: 1 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.700  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.701  I/System.out:    _amount=110
                      2022-01-08 07:32:14.701  I/System.out:    _calory=238.243
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.701  I/System.out: 2 {
                      2022-01-08 07:32:14.701  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.701  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.701  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.701  I/System.out:    _amount=1
                      2022-01-08 07:32:14.701  I/System.out:    _calory=2.16585
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 3 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.702  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.702  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.702  I/System.out:    _amount=17
                      2022-01-08 07:32:14.702  I/System.out:    _calory=3.48774
                      2022-01-08 07:32:14.702  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.702  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 4 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.703  I/System.out:    _amount=10
                      2022-01-08 07:32:14.703  I/System.out:    _calory=382.243
                      2022-01-08 07:32:14.703  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.703  I/System.out: }
                      2022-01-08 07:32:14.703  I/System.out: 5 {
                      2022-01-08 07:32:14.703  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.703  I/System.out:    _amount=3
                      2022-01-08 07:32:14.704  I/System.out:    _calory=5.16585
                      2022-01-08 07:32:14.704  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.704  I/System.out: }
                      2022-01-08 07:32:14.704  I/System.out: <<<<<
                      
                      class MyData {
                          public static final String TABLE_NAME = "_mydata";
                          public static final String COLUMN_FOOD_ID = "_food_id";
                          public static final String COLUMN_FOOD_NAME = "_food_name";
                          long food_id;
                          String food_name;
                          Unit[] units;
                      
                          public MyData(long food_id, String food_name, Unit[] units) {
                              this.food_id = food_id;
                              this.food_name = food_name;
                              this.units = units;
                          }
                      }
                      
                      class Unit {
                          public static final String TABLE_NAME = "_unit";
                          public static final String COLUMN_UNIT = "_unit";
                          public static final String COLUMN_AMOUNT = "_amount";
                          public static final String COLUMN_CALORY = "_calory";
                          public static final String COLUMN_FOOD_ID_PARENT ="parent_food_id";
                          String unit;
                          double amount;
                          double calory;
                      
                          public Unit(String unit, double amount, double calory) {
                              this.unit = unit;
                              this.amount = amount;
                              this.calory = calory;
                          }
                      }
                      
                      class DatabaseHelper extends SQLiteOpenHelper {
                      
                          public static final String DATABASE_NAME = "my_database.db";
                          public static final int DATABASE_VERSION = 1;
                      
                          private SQLiteDatabase db;
                          private static volatile DatabaseHelper instance = null;
                          private DatabaseHelper(Context context) {
                              super(context,DATABASE_NAME,null,DATABASE_VERSION);
                              db = this.getWritableDatabase();
                          }
                      
                          /* Use a singleton approach */
                          public static DatabaseHelper getInstance(Context context) {
                              if (instance == null) {
                                  instance = new DatabaseHelper(context);
                              }
                              return instance;
                          }
                      
                          @Override
                          public void onCreate(SQLiteDatabase db) {
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + MyData.TABLE_NAME + "(" +
                                              MyData.COLUMN_FOOD_ID + " INTEGER PRIMARY KEY," +
                                              MyData.COLUMN_FOOD_NAME + " TEXT" +
                                              ")"
                              );
                      
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + Unit.TABLE_NAME + "(" +
                                              Unit.COLUMN_UNIT + " TEXT," +
                                              Unit.COLUMN_AMOUNT + " REAL," +
                                              Unit.COLUMN_CALORY + " REAL," +
                                              Unit.COLUMN_FOOD_ID_PARENT +
                                              /* Foreign Key Constraint to enforce referential integrity*/
                                              " INTEGER REFERENCES " + MyData.TABLE_NAME + "(" + MyData.COLUMN_FOOD_ID + ") " +
                                              /* These make maintaining referential integrity easier */
                                              "ON DELETE CASCADE " +
                                              "ON UPDATE CASCADE, " +
                                              /* define the primary key */
                                              " PRIMARY KEY(" +
                                              Unit.COLUMN_UNIT + "," + Unit.COLUMN_AMOUNT + "," + Unit.COLUMN_CALORY +
                                              ")" +
                                              ")"
                              );
                      
                          }
                      
                          @Override
                          public void onUpgrade(SQLiteDatabase db, int i, int i1) {
                              /* not expecting to increase the database version so leave this to do nothing */
                          }
                      
                          public long insertMyData(MyData myData) {
                              ContentValues cv = new ContentValues();
                              cv.put(MyData.COLUMN_FOOD_ID,myData.food_id);
                              cv.put(MyData.COLUMN_FOOD_NAME,myData.food_name);
                              return db.insert(MyData.TABLE_NAME,null,cv);
                          }
                      
                          public long insertUnit(Unit unit, long parentId) {
                              ContentValues cv = new ContentValues();
                              cv.put(Unit.COLUMN_UNIT,unit.unit);
                              cv.put(Unit.COLUMN_AMOUNT,unit.amount);
                              cv.put(Unit.COLUMN_CALORY,unit.calory);
                              cv.put(Unit.COLUMN_FOOD_ID_PARENT,parentId);
                              return db.insert(Unit.TABLE_NAME,null,cv);
                          }
                      
                          public void massInsert(String jsonString) {
                              MyData[] extracted = new Gson().fromJson(jsonString,MyData[].class);
                              db.beginTransaction();
                              for(MyData m: new Gson().fromJson(jsonString,MyData[].class)) {
                                  long food_id = insertMyData(m);
                                  if (food_id > 0) {
                                      for(Unit u: m.units) {
                                          insertUnit(u,food_id);
                                      }
                                  }
                              }
                              db.setTransactionSuccessful();
                              db.endTransaction();
                          }
                      }
                      
                      public class MainActivity extends AppCompatActivity {
                      
                          MyData[] TESTDATA = {
                                  new MyData(
                                          1,
                                          "Bat",
                                          new Unit[]{
                                                  new Unit("Unit A",15.0000,32.4877372383),
                                                  new Unit("Unit C",110.0000,238.243404414),
                                                  new Unit("Unit F",1.0000,2.16584914922)
                                          }
                                          ),
                                  new MyData(
                                          2,
                                          "Another",
                                          new Unit[]{
                                                  new Unit("Unit A",17.0000,3.4877372383),
                                                  new Unit("Unit C",10.0000,382.243404414),
                                                  new Unit("Unit F",3.0000,5.16584914922)
                                          }
                                  ),
                          };
                      
                          DatabaseHelper dbHelper;
                      
                          @Override
                          protected void onCreate(Bundle savedInstanceState) {
                              super.onCreate(savedInstanceState);
                              setContentView(R.layout.activity_main);
                      
                              String test = new Gson().toJson(TESTDATA);
                              Log.d("APPINFO","TESTDATA as JSON is\n\t" + test);
                              //MyData[] extracted = new Gson().fromJson(test,MyData[].class);
                      
                              dbHelper = DatabaseHelper.getInstance(this); // Prepare to use the database
                              dbHelper.massInsert(test); // Actually use the database to insert the data
                      
                              /* Example of extracting data using a JOIN to combine the MyData and the related Units */
                              Cursor csr =  dbHelper.getWritableDatabase().query(
                                      MyData.TABLE_NAME + " JOIN " + Unit.TABLE_NAME + " ON " + Unit.COLUMN_FOOD_ID_PARENT + "=" + MyData.COLUMN_FOOD_ID,
                                      null,null,null,null,null,null
                                      );
                              DatabaseUtils.dumpCursor(csr);
                              csr.close();
                      
                          }
                      }
                      
                      2022-01-08 07:32:14.666  D/APPINFO: TESTDATA as JSON is
                              [{"food_id":1,"food_name":"Bat","units":[{"amount":15.0,"calory":32.4877372383,"unit":"Unit A"},{"amount":110.0,"calory":238.243404414,"unit":"Unit C"},{"amount":1.0,"calory":2.16584914922,"unit":"Unit F"}]},{"food_id":2,"food_name":"Another","units":[{"amount":17.0,"calory":3.4877372383,"unit":"Unit A"},{"amount":10.0,"calory":382.243404414,"unit":"Unit C"},{"amount":3.0,"calory":5.16584914922,"unit":"Unit F"}]}]
                      
                      2022-01-08 07:32:14.698  I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@f302fce
                      2022-01-08 07:32:14.699  I/System.out: 0 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.699  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.699  I/System.out:    _amount=15
                      2022-01-08 07:32:14.699  I/System.out:    _calory=32.4877
                      2022-01-08 07:32:14.699  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.699  I/System.out: }
                      2022-01-08 07:32:14.699  I/System.out: 1 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.700  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.701  I/System.out:    _amount=110
                      2022-01-08 07:32:14.701  I/System.out:    _calory=238.243
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.701  I/System.out: 2 {
                      2022-01-08 07:32:14.701  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.701  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.701  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.701  I/System.out:    _amount=1
                      2022-01-08 07:32:14.701  I/System.out:    _calory=2.16585
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 3 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.702  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.702  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.702  I/System.out:    _amount=17
                      2022-01-08 07:32:14.702  I/System.out:    _calory=3.48774
                      2022-01-08 07:32:14.702  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.702  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 4 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.703  I/System.out:    _amount=10
                      2022-01-08 07:32:14.703  I/System.out:    _calory=382.243
                      2022-01-08 07:32:14.703  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.703  I/System.out: }
                      2022-01-08 07:32:14.703  I/System.out: 5 {
                      2022-01-08 07:32:14.703  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.703  I/System.out:    _amount=3
                      2022-01-08 07:32:14.704  I/System.out:    _calory=5.16585
                      2022-01-08 07:32:14.704  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.704  I/System.out: }
                      2022-01-08 07:32:14.704  I/System.out: <<<<<
                      
                      class MyData {
                          public static final String TABLE_NAME = "_mydata";
                          public static final String COLUMN_FOOD_ID = "_food_id";
                          public static final String COLUMN_FOOD_NAME = "_food_name";
                          long food_id;
                          String food_name;
                          Unit[] units;
                      
                          public MyData(long food_id, String food_name, Unit[] units) {
                              this.food_id = food_id;
                              this.food_name = food_name;
                              this.units = units;
                          }
                      }
                      
                      class Unit {
                          public static final String TABLE_NAME = "_unit";
                          public static final String COLUMN_UNIT = "_unit";
                          public static final String COLUMN_AMOUNT = "_amount";
                          public static final String COLUMN_CALORY = "_calory";
                          public static final String COLUMN_FOOD_ID_PARENT ="parent_food_id";
                          String unit;
                          double amount;
                          double calory;
                      
                          public Unit(String unit, double amount, double calory) {
                              this.unit = unit;
                              this.amount = amount;
                              this.calory = calory;
                          }
                      }
                      
                      class DatabaseHelper extends SQLiteOpenHelper {
                      
                          public static final String DATABASE_NAME = "my_database.db";
                          public static final int DATABASE_VERSION = 1;
                      
                          private SQLiteDatabase db;
                          private static volatile DatabaseHelper instance = null;
                          private DatabaseHelper(Context context) {
                              super(context,DATABASE_NAME,null,DATABASE_VERSION);
                              db = this.getWritableDatabase();
                          }
                      
                          /* Use a singleton approach */
                          public static DatabaseHelper getInstance(Context context) {
                              if (instance == null) {
                                  instance = new DatabaseHelper(context);
                              }
                              return instance;
                          }
                      
                          @Override
                          public void onCreate(SQLiteDatabase db) {
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + MyData.TABLE_NAME + "(" +
                                              MyData.COLUMN_FOOD_ID + " INTEGER PRIMARY KEY," +
                                              MyData.COLUMN_FOOD_NAME + " TEXT" +
                                              ")"
                              );
                      
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + Unit.TABLE_NAME + "(" +
                                              Unit.COLUMN_UNIT + " TEXT," +
                                              Unit.COLUMN_AMOUNT + " REAL," +
                                              Unit.COLUMN_CALORY + " REAL," +
                                              Unit.COLUMN_FOOD_ID_PARENT +
                                              /* Foreign Key Constraint to enforce referential integrity*/
                                              " INTEGER REFERENCES " + MyData.TABLE_NAME + "(" + MyData.COLUMN_FOOD_ID + ") " +
                                              /* These make maintaining referential integrity easier */
                                              "ON DELETE CASCADE " +
                                              "ON UPDATE CASCADE, " +
                                              /* define the primary key */
                                              " PRIMARY KEY(" +
                                              Unit.COLUMN_UNIT + "," + Unit.COLUMN_AMOUNT + "," + Unit.COLUMN_CALORY +
                                              ")" +
                                              ")"
                              );
                      
                          }
                      
                          @Override
                          public void onUpgrade(SQLiteDatabase db, int i, int i1) {
                              /* not expecting to increase the database version so leave this to do nothing */
                          }
                      
                          public long insertMyData(MyData myData) {
                              ContentValues cv = new ContentValues();
                              cv.put(MyData.COLUMN_FOOD_ID,myData.food_id);
                              cv.put(MyData.COLUMN_FOOD_NAME,myData.food_name);
                              return db.insert(MyData.TABLE_NAME,null,cv);
                          }
                      
                          public long insertUnit(Unit unit, long parentId) {
                              ContentValues cv = new ContentValues();
                              cv.put(Unit.COLUMN_UNIT,unit.unit);
                              cv.put(Unit.COLUMN_AMOUNT,unit.amount);
                              cv.put(Unit.COLUMN_CALORY,unit.calory);
                              cv.put(Unit.COLUMN_FOOD_ID_PARENT,parentId);
                              return db.insert(Unit.TABLE_NAME,null,cv);
                          }
                      
                          public void massInsert(String jsonString) {
                              MyData[] extracted = new Gson().fromJson(jsonString,MyData[].class);
                              db.beginTransaction();
                              for(MyData m: new Gson().fromJson(jsonString,MyData[].class)) {
                                  long food_id = insertMyData(m);
                                  if (food_id > 0) {
                                      for(Unit u: m.units) {
                                          insertUnit(u,food_id);
                                      }
                                  }
                              }
                              db.setTransactionSuccessful();
                              db.endTransaction();
                          }
                      }
                      
                      public class MainActivity extends AppCompatActivity {
                      
                          MyData[] TESTDATA = {
                                  new MyData(
                                          1,
                                          "Bat",
                                          new Unit[]{
                                                  new Unit("Unit A",15.0000,32.4877372383),
                                                  new Unit("Unit C",110.0000,238.243404414),
                                                  new Unit("Unit F",1.0000,2.16584914922)
                                          }
                                          ),
                                  new MyData(
                                          2,
                                          "Another",
                                          new Unit[]{
                                                  new Unit("Unit A",17.0000,3.4877372383),
                                                  new Unit("Unit C",10.0000,382.243404414),
                                                  new Unit("Unit F",3.0000,5.16584914922)
                                          }
                                  ),
                          };
                      
                          DatabaseHelper dbHelper;
                      
                          @Override
                          protected void onCreate(Bundle savedInstanceState) {
                              super.onCreate(savedInstanceState);
                              setContentView(R.layout.activity_main);
                      
                              String test = new Gson().toJson(TESTDATA);
                              Log.d("APPINFO","TESTDATA as JSON is\n\t" + test);
                              //MyData[] extracted = new Gson().fromJson(test,MyData[].class);
                      
                              dbHelper = DatabaseHelper.getInstance(this); // Prepare to use the database
                              dbHelper.massInsert(test); // Actually use the database to insert the data
                      
                              /* Example of extracting data using a JOIN to combine the MyData and the related Units */
                              Cursor csr =  dbHelper.getWritableDatabase().query(
                                      MyData.TABLE_NAME + " JOIN " + Unit.TABLE_NAME + " ON " + Unit.COLUMN_FOOD_ID_PARENT + "=" + MyData.COLUMN_FOOD_ID,
                                      null,null,null,null,null,null
                                      );
                              DatabaseUtils.dumpCursor(csr);
                              csr.close();
                      
                          }
                      }
                      
                      2022-01-08 07:32:14.666  D/APPINFO: TESTDATA as JSON is
                              [{"food_id":1,"food_name":"Bat","units":[{"amount":15.0,"calory":32.4877372383,"unit":"Unit A"},{"amount":110.0,"calory":238.243404414,"unit":"Unit C"},{"amount":1.0,"calory":2.16584914922,"unit":"Unit F"}]},{"food_id":2,"food_name":"Another","units":[{"amount":17.0,"calory":3.4877372383,"unit":"Unit A"},{"amount":10.0,"calory":382.243404414,"unit":"Unit C"},{"amount":3.0,"calory":5.16584914922,"unit":"Unit F"}]}]
                      
                      2022-01-08 07:32:14.698  I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@f302fce
                      2022-01-08 07:32:14.699  I/System.out: 0 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.699  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.699  I/System.out:    _amount=15
                      2022-01-08 07:32:14.699  I/System.out:    _calory=32.4877
                      2022-01-08 07:32:14.699  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.699  I/System.out: }
                      2022-01-08 07:32:14.699  I/System.out: 1 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.700  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.701  I/System.out:    _amount=110
                      2022-01-08 07:32:14.701  I/System.out:    _calory=238.243
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.701  I/System.out: 2 {
                      2022-01-08 07:32:14.701  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.701  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.701  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.701  I/System.out:    _amount=1
                      2022-01-08 07:32:14.701  I/System.out:    _calory=2.16585
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 3 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.702  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.702  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.702  I/System.out:    _amount=17
                      2022-01-08 07:32:14.702  I/System.out:    _calory=3.48774
                      2022-01-08 07:32:14.702  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.702  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 4 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.703  I/System.out:    _amount=10
                      2022-01-08 07:32:14.703  I/System.out:    _calory=382.243
                      2022-01-08 07:32:14.703  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.703  I/System.out: }
                      2022-01-08 07:32:14.703  I/System.out: 5 {
                      2022-01-08 07:32:14.703  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.703  I/System.out:    _amount=3
                      2022-01-08 07:32:14.704  I/System.out:    _calory=5.16585
                      2022-01-08 07:32:14.704  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.704  I/System.out: }
                      2022-01-08 07:32:14.704  I/System.out: <<<<<
                      
                      class MyData {
                          public static final String TABLE_NAME = "_mydata";
                          public static final String COLUMN_FOOD_ID = "_food_id";
                          public static final String COLUMN_FOOD_NAME = "_food_name";
                          long food_id;
                          String food_name;
                          Unit[] units;
                      
                          public MyData(long food_id, String food_name, Unit[] units) {
                              this.food_id = food_id;
                              this.food_name = food_name;
                              this.units = units;
                          }
                      }
                      
                      class Unit {
                          public static final String TABLE_NAME = "_unit";
                          public static final String COLUMN_UNIT = "_unit";
                          public static final String COLUMN_AMOUNT = "_amount";
                          public static final String COLUMN_CALORY = "_calory";
                          public static final String COLUMN_FOOD_ID_PARENT ="parent_food_id";
                          String unit;
                          double amount;
                          double calory;
                      
                          public Unit(String unit, double amount, double calory) {
                              this.unit = unit;
                              this.amount = amount;
                              this.calory = calory;
                          }
                      }
                      
                      class DatabaseHelper extends SQLiteOpenHelper {
                      
                          public static final String DATABASE_NAME = "my_database.db";
                          public static final int DATABASE_VERSION = 1;
                      
                          private SQLiteDatabase db;
                          private static volatile DatabaseHelper instance = null;
                          private DatabaseHelper(Context context) {
                              super(context,DATABASE_NAME,null,DATABASE_VERSION);
                              db = this.getWritableDatabase();
                          }
                      
                          /* Use a singleton approach */
                          public static DatabaseHelper getInstance(Context context) {
                              if (instance == null) {
                                  instance = new DatabaseHelper(context);
                              }
                              return instance;
                          }
                      
                          @Override
                          public void onCreate(SQLiteDatabase db) {
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + MyData.TABLE_NAME + "(" +
                                              MyData.COLUMN_FOOD_ID + " INTEGER PRIMARY KEY," +
                                              MyData.COLUMN_FOOD_NAME + " TEXT" +
                                              ")"
                              );
                      
                              db.execSQL(
                                      "CREATE TABLE IF NOT EXISTS " + Unit.TABLE_NAME + "(" +
                                              Unit.COLUMN_UNIT + " TEXT," +
                                              Unit.COLUMN_AMOUNT + " REAL," +
                                              Unit.COLUMN_CALORY + " REAL," +
                                              Unit.COLUMN_FOOD_ID_PARENT +
                                              /* Foreign Key Constraint to enforce referential integrity*/
                                              " INTEGER REFERENCES " + MyData.TABLE_NAME + "(" + MyData.COLUMN_FOOD_ID + ") " +
                                              /* These make maintaining referential integrity easier */
                                              "ON DELETE CASCADE " +
                                              "ON UPDATE CASCADE, " +
                                              /* define the primary key */
                                              " PRIMARY KEY(" +
                                              Unit.COLUMN_UNIT + "," + Unit.COLUMN_AMOUNT + "," + Unit.COLUMN_CALORY +
                                              ")" +
                                              ")"
                              );
                      
                          }
                      
                          @Override
                          public void onUpgrade(SQLiteDatabase db, int i, int i1) {
                              /* not expecting to increase the database version so leave this to do nothing */
                          }
                      
                          public long insertMyData(MyData myData) {
                              ContentValues cv = new ContentValues();
                              cv.put(MyData.COLUMN_FOOD_ID,myData.food_id);
                              cv.put(MyData.COLUMN_FOOD_NAME,myData.food_name);
                              return db.insert(MyData.TABLE_NAME,null,cv);
                          }
                      
                          public long insertUnit(Unit unit, long parentId) {
                              ContentValues cv = new ContentValues();
                              cv.put(Unit.COLUMN_UNIT,unit.unit);
                              cv.put(Unit.COLUMN_AMOUNT,unit.amount);
                              cv.put(Unit.COLUMN_CALORY,unit.calory);
                              cv.put(Unit.COLUMN_FOOD_ID_PARENT,parentId);
                              return db.insert(Unit.TABLE_NAME,null,cv);
                          }
                      
                          public void massInsert(String jsonString) {
                              MyData[] extracted = new Gson().fromJson(jsonString,MyData[].class);
                              db.beginTransaction();
                              for(MyData m: new Gson().fromJson(jsonString,MyData[].class)) {
                                  long food_id = insertMyData(m);
                                  if (food_id > 0) {
                                      for(Unit u: m.units) {
                                          insertUnit(u,food_id);
                                      }
                                  }
                              }
                              db.setTransactionSuccessful();
                              db.endTransaction();
                          }
                      }
                      
                      public class MainActivity extends AppCompatActivity {
                      
                          MyData[] TESTDATA = {
                                  new MyData(
                                          1,
                                          "Bat",
                                          new Unit[]{
                                                  new Unit("Unit A",15.0000,32.4877372383),
                                                  new Unit("Unit C",110.0000,238.243404414),
                                                  new Unit("Unit F",1.0000,2.16584914922)
                                          }
                                          ),
                                  new MyData(
                                          2,
                                          "Another",
                                          new Unit[]{
                                                  new Unit("Unit A",17.0000,3.4877372383),
                                                  new Unit("Unit C",10.0000,382.243404414),
                                                  new Unit("Unit F",3.0000,5.16584914922)
                                          }
                                  ),
                          };
                      
                          DatabaseHelper dbHelper;
                      
                          @Override
                          protected void onCreate(Bundle savedInstanceState) {
                              super.onCreate(savedInstanceState);
                              setContentView(R.layout.activity_main);
                      
                              String test = new Gson().toJson(TESTDATA);
                              Log.d("APPINFO","TESTDATA as JSON is\n\t" + test);
                              //MyData[] extracted = new Gson().fromJson(test,MyData[].class);
                      
                              dbHelper = DatabaseHelper.getInstance(this); // Prepare to use the database
                              dbHelper.massInsert(test); // Actually use the database to insert the data
                      
                              /* Example of extracting data using a JOIN to combine the MyData and the related Units */
                              Cursor csr =  dbHelper.getWritableDatabase().query(
                                      MyData.TABLE_NAME + " JOIN " + Unit.TABLE_NAME + " ON " + Unit.COLUMN_FOOD_ID_PARENT + "=" + MyData.COLUMN_FOOD_ID,
                                      null,null,null,null,null,null
                                      );
                              DatabaseUtils.dumpCursor(csr);
                              csr.close();
                      
                          }
                      }
                      
                      2022-01-08 07:32:14.666  D/APPINFO: TESTDATA as JSON is
                              [{"food_id":1,"food_name":"Bat","units":[{"amount":15.0,"calory":32.4877372383,"unit":"Unit A"},{"amount":110.0,"calory":238.243404414,"unit":"Unit C"},{"amount":1.0,"calory":2.16584914922,"unit":"Unit F"}]},{"food_id":2,"food_name":"Another","units":[{"amount":17.0,"calory":3.4877372383,"unit":"Unit A"},{"amount":10.0,"calory":382.243404414,"unit":"Unit C"},{"amount":3.0,"calory":5.16584914922,"unit":"Unit F"}]}]
                      
                      2022-01-08 07:32:14.698  I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@f302fce
                      2022-01-08 07:32:14.699  I/System.out: 0 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.699  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.699  I/System.out:    _amount=15
                      2022-01-08 07:32:14.699  I/System.out:    _calory=32.4877
                      2022-01-08 07:32:14.699  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.699  I/System.out: }
                      2022-01-08 07:32:14.699  I/System.out: 1 {
                      2022-01-08 07:32:14.699  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.699  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.700  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.701  I/System.out:    _amount=110
                      2022-01-08 07:32:14.701  I/System.out:    _calory=238.243
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.701  I/System.out: 2 {
                      2022-01-08 07:32:14.701  I/System.out:    _food_id=1
                      2022-01-08 07:32:14.701  I/System.out:    _food_name=Bat
                      2022-01-08 07:32:14.701  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.701  I/System.out:    _amount=1
                      2022-01-08 07:32:14.701  I/System.out:    _calory=2.16585
                      2022-01-08 07:32:14.701  I/System.out:    parent_food_id=1
                      2022-01-08 07:32:14.701  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 3 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.702  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.702  I/System.out:    _unit=Unit A
                      2022-01-08 07:32:14.702  I/System.out:    _amount=17
                      2022-01-08 07:32:14.702  I/System.out:    _calory=3.48774
                      2022-01-08 07:32:14.702  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.702  I/System.out: }
                      2022-01-08 07:32:14.702  I/System.out: 4 {
                      2022-01-08 07:32:14.702  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit C
                      2022-01-08 07:32:14.703  I/System.out:    _amount=10
                      2022-01-08 07:32:14.703  I/System.out:    _calory=382.243
                      2022-01-08 07:32:14.703  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.703  I/System.out: }
                      2022-01-08 07:32:14.703  I/System.out: 5 {
                      2022-01-08 07:32:14.703  I/System.out:    _food_id=2
                      2022-01-08 07:32:14.703  I/System.out:    _food_name=Another
                      2022-01-08 07:32:14.703  I/System.out:    _unit=Unit F
                      2022-01-08 07:32:14.703  I/System.out:    _amount=3
                      2022-01-08 07:32:14.704  I/System.out:    _calory=5.16585
                      2022-01-08 07:32:14.704  I/System.out:    parent_food_id=2
                      2022-01-08 07:32:14.704  I/System.out: }
                      2022-01-08 07:32:14.704  I/System.out: <<<<<
                      

                      why is pdf from internal storage not showing in webview

                      copy iconCopydownload iconDownload
                      String pdfUrl = "https://docs.google.com/gview?embedded=true&url=" + realPdfUrl;
                      

                      Getting id from one json and finding name of that code in json

                      copy iconCopydownload iconDownload
                      public String loadJSONFromResource() {
                          String json = null;
                          try {
                              InputStream is = getActivity().getResources().openRawResource(R.raw.coindata);
                              int size = is.available();
                              byte[] buffer = new byte[size];
                              is.read(buffer);
                              is.close();
                              json = new String(buffer, "UTF-8");
                          } catch (IOException ex) {
                              ex.printStackTrace();
                              return null;
                          }
                          return json;
                      }
                      
                      CalendarCoinModal obj;
                      int searchId = somevalue;
                      for(CalendarCoinModal currObj : calendarCoinModalArrayList) {
                          if(currObj.id == somevalue) {
                              obj = currObj;
                              break;
                          }
                      }
                      
                      public String loadJSONFromResource() {
                          String json = null;
                          try {
                              InputStream is = getActivity().getResources().openRawResource(R.raw.coindata);
                              int size = is.available();
                              byte[] buffer = new byte[size];
                              is.read(buffer);
                              is.close();
                              json = new String(buffer, "UTF-8");
                          } catch (IOException ex) {
                              ex.printStackTrace();
                              return null;
                          }
                          return json;
                      }
                      
                      CalendarCoinModal obj;
                      int searchId = somevalue;
                      for(CalendarCoinModal currObj : calendarCoinModalArrayList) {
                          if(currObj.id == somevalue) {
                              obj = currObj;
                              break;
                          }
                      }
                      

                      Android wear OS retrieving stepcounter in background

                      copy iconCopydownload iconDownload
                      @Override
                      protected void onPause() {
                          super.onPause();
                          sensorManager.unregisterListener(this);
                      }
                      

                      Error extracting an `.aab` file: Invalid dex file indices, expecting file 'classes٢.dex' but found 'classes2.dex'

                      copy iconCopydownload iconDownload
                      release {
                          minifyEnabled false
                          .......
                      }
                      

                      how to stop letter repeating itself python

                      copy iconCopydownload iconDownload
                      sorted_jumbled_word = sorted(a)
                      for word in val1:
                          if len(sorted_jumbled_word) == len(word) and sorted(word) == sorted_jumbled_word:
                              print(word)
                      

                      Opening an Activity from a class

                      copy iconCopydownload iconDownload
                      UserAuthentication userAuthentication = new UserAuthentication(SignUpActivity.this);
                                       userAuthentication.SignUp(activityContext ,userName, userSignUpEmail, userPassword));
                      
                      Intent intent = new Intent(conext,NextActivity.class);
                      startActivity(intent);
                      

                      Pass YouTube API JSONObject Result to Method

                      copy iconCopydownload iconDownload
                      try {
                                                  JSONArray jsonArray = response.getJSONArray("items");
                      
                                                  for (int i = 0; i < jsonArray.length(); i++) {
                                                      JSONObject jsonObject = jsonArray.optJSONObject(i);
                                                      JSONObject jsonArray1 = jsonObject.getJSONObject("id");
                                                      String videoid = jsonArray1.optString("videoId");
                                                      ytapi.setText(videoid);
                                                  }
                      
                                              } catch (JSONException e) {
                                                  e.printStackTrace();
                                              }
                      

                      How to return single integer value from Volley in Android?

                      copy iconCopydownload iconDownload
                      public void fetchVersionNumber() {
                      
                          StringRequest stringRequest = new StringRequest(Request.Method.POST, GET_VERSION_NUMBER,
                                  new Response.Listener<String>() {
                                      @Override
                                      public void onResponse(String response) {
                                          try {
                                              JSONObject object = new JSONObject(response);
                                              JSONArray jsonArray = object.getJSONArray("result");
                                              JSONObject jsonObject = jsonArray.getJSONObject(0);
                      
                                              vNumber = jsonObject.getInt("version");
                                              compareAndUpdate(vNumber)
                      
                                          } catch (JSONException e) {
                                              e.printStackTrace();
                                              Log.d(TAG, "JSONException: " + e);
                                          }
                                      }
                                  },
                                  new Response.ErrorListener() {
                                      @Override
                                      public void onErrorResponse(VolleyError error) {
                                          Log.d(TAG, "VolleyError: " + error);
                                      }
                                  });
                      
                          RequestQueue requestQueue = Volley.newRequestQueue(context);
                          requestQueue.add(stringRequest);
                      }
                      
                      public void compareAndUpdate(int vNumber){
                      
                      //compare and do your operation
                      // Get from sharedPref and compare
                      }
                      

                      See all related Code Snippets

                      Community Discussions

                      Trending Discussions on volley
                      • Android app communication with local apache server
                      • Project update recommended: Android Gradle Plugin can be upgraded. Error message: Can not find AGP version in build files
                      • How can I store data with nested object data in Android? [Room]
                      • why is pdf from internal storage not showing in webview
                      • Getting id from one json and finding name of that code in json
                      • Android wear OS retrieving stepcounter in background
                      • Error extracting an `.aab` file: Invalid dex file indices, expecting file 'classes٢.dex' but found 'classes2.dex'
                      • com.android.volley.AuthFailureError Using GET in StringRequest with Volley Library
                      • how to stop letter repeating itself python
                      • Opening an Activity from a class
                      Trending Discussions on volley

                      QUESTION

                      Android app communication with local apache server

                      Asked 2022-Mar-23 at 21:55

                      I am new to Android dev, I have started using Android Studio with Kotlin few days. I run into an issue today which is : how can my app communicate with my local server (XAMPP : Apache and MYSQL) I am running Windows 10, and using my real physical phone instead of the emulator (API 30) since the emulator works so slow for me.

                      I have a simple php app that only returns "hi", I tried many ways to use AJAX requests but the one closest to working with is Android Volley, here is my code:

                             val queue = Volley.newRequestQueue(this)
                              val url = "http://mohe.pagekite.me"
                              lateinit var qq : String
                              val stringRequest = StringRequest(
                                  Request.Method.GET, url,
                                  { response ->
                                      qq = "Response is: ${response.substring(0, 500)}"
                                      val toast = Toast.makeText(applicationContext, qq, Toast.LENGTH_LONG)
                                      toast.show()
                                  },
                                  { error-> qq = error.toString()
                                      val toast = Toast.makeText(applicationContext, qq, Toast.LENGTH_LONG)
                                      toast.show()
                                  })
                      
                              queue.add(stringRequest)
                      

                      at first I used my IP since we are connected to the same wifi (hotspot) and since I can actually open my localhost in my phone's browser, but it didn't work inside the code. (I had an error : java.net.MalformedURLException: no protocol), I looked around and read that Volley doesn't support IP addresses, so I used PAGEKITE to make my localhost accessible to the internet with a readable link, but now I am getting this error instead : cleartext http traffic to not permitted

                      I added this android:usesCleartextTraffic="true" to my manifest.xml and created network_security_config.xml :

                      <?xml version="1.0" encoding="utf-8"?>
                      <network-security-config>
                          <domain-config cleartextTrafficPermitted="true">
                              <base-config cleartextTrafficPermitted="true"/>
                      
                              <domain includeSubdomains="true">api.example.com(to be adjusted)</domain>
                              <trust-anchors>
                                  <certificates src="system" />
                              </trust-anchors>
                          </domain-config>
                      </network-security-config>
                      

                      But the issue is still the same. I tried the same thing with google.com also I tried my php file but in my webhosting, and it worked just fine, so the issue is somewhere in my localhost I would assume, probably because I am not using a secure connection (https) ?

                      This bugged me because how else would I be able to make an app with a database if I can't comminute with my localhost ? using my real webhost slows the development process and I can't get my head around this issue. How do you develop and test your app with your local server or am I doing everything wrong ?

                      Edit : the purpose of my app is to be able to login and read/edit some data from any device.

                      ANSWER

                      Answered 2022-Mar-23 at 21:55

                      Solved : I forgot to add my URL in network_security_config.xml

                      <domain includeSubdomains="true">192.168.56.172</domain>

                      Now it works with both my IP address or my URL.

                      Source https://stackoverflow.com/questions/71531867

                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                      Vulnerabilities

                      No vulnerabilities reported

                      Install volley

                      You can download it from GitHub.
                      You can use volley like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the volley component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

                      Support

                      For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Explore Related Topics

                      Share this Page

                      share link
                      Consider Popular Learning Libraries
                      Try Top Libraries by adamrocker
                      Compare Learning Libraries with Highest Support
                      Compare Learning Libraries with Highest Quality
                      Compare Learning Libraries with Highest Security
                      Compare Learning Libraries with Permissive License
                      Compare Learning Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.