Sending and receiving of JSON data to and from Android StudioReceiving data from a databaseFilling a spinner...

What is the in-universe cost of a TIE fighter?

Can a hotel cancel a confirmed reservation?

How do I say "Brexit" in Latin?

Blindfold battle as a gladiatorial spectacle - what are the tactics and communication methods?

Is there a standard way to treat events with unknown times (missing time data)?

Would a National Army of mercenaries be a feasible idea?

What's a good word to describe a public place that looks like it wouldn't be rough?

My cat mixes up the floors in my building. How can I help him?

What to do when being responsible for data protection in your lab, yet advice is ignored?

How to acknowledge an embarrassing job interview, now that I work directly with the interviewer?

Broken patches on a road

Does Windows 10's telemetry include sending *.doc files if Word crashed?

What is the purpose of easy combat scenarios that don't need resource expenditure?

Is casting an attack cantrip from a wand an "attack action made with a magic weapon"?

Can I write a book of my D&D game?

Difference between two similar commands to activate a Python venv

Find x angle in triangle

Why don't American passenger airlines operate dedicated cargo flights any more?

Why did other German political parties disband so fast when Hitler was appointed chancellor?

What is this metal M-shaped device for?

Magento 2 : Call Helper Without Using __construct in Own Module

How to avoid Replace substituting subscripts?

Why does a metal block make a shrill sound but not a wooden block upon hammering?

Strange Sign on Lab Door



Sending and receiving of JSON data to and from Android Studio


Receiving data from a databaseFilling a spinner from JSON web dataAndroid “Search” Activity and corresponding XMLSimplified if return suggestion from Android StudioImplementation of stackAndroid Studio Background Service to Update LocationPulling from data from SQLite DB on AndroidSimple calculator in Android StudioUnit Testing Android StudioPassword and confirm password validation in Android Studio













3












$begingroup$


I'm currently developing an app that requires sending and receiving of data from android studio going to MySQL and then data coming from MySQL will be saved from the SQLite. I need advice on how to make the process faster. Right now I'm inserting 80,000 + rows of data coming from MySQL and then saving it to SQLite and that process lasts around 25-30 minutes.



rowItem.php



<?php

require "init.php";

$serial = $_POST['mySerial'];

$sql = "select ITEMCODE, DESCRIPTION, BRAND from items where SERIAL_NO = '" .$serial. "'";
$result = mysqli_query($con, $sql);

$data =array();

while($row = mysqli_fetch_array($result)) {
$row['ITEMCODE'] = mb_convert_encoding($row['ITEMCODE'], 'UTF-8', 'UTF-8');
$row['DESCRIPTION'] = mb_convert_encoding($row['DESCRIPTION'], 'UTF-8', 'UTF-8');
$row['BRAND'] = mb_convert_encoding($row['BRAND'], 'UTF-8', 'UTF-8');
array_push($data, array('ITEMCODE' => $row['ITEMCODE'], 'DESCRIPTION' => $row['DESCRIPTION'], 'BRAND' => $row['BRAND']));
}

$json = json_encode(array("allItems"=>$data));
echo $json;

?>


DatabaseOperations.java



    public class DatabaseOperations extends SQLiteOpenHelper {
public static final int dbVersion = 1;

public String CREATE_ITEMS_TABLE = "CREATE TABLE " + TableData.TableInfo.TB_ITEMS +
" (" + TableData.TableInfo.COL_ITEMS_ITEMCODE + " VARCHAR(20) PRIMARY KEY NOT NULL, " +
TableData.TableInfo.COL_ITEMS_DESCRIPTION + " VARCHAR(50), " +
TableData.TableInfo.COL_ITEMS_BRAND + " VARCHAR(10), " +
TableData.TableInfo.COL_ITEMS_BARCODE + " VARCHAR(20));";

public DatabaseOperations(Context context) {
super(context, TableData.TableInfo.DB_NAME, null, dbVersion);
}

@Override
public void onCreate(SQLiteDatabase sdb) {
sdb.execSQL(CREATE_ITEMS_TABLE);
}

public void insertItems (DatabaseOperations dop,
String itemCode, String brand, String desc) {
SQLiteDatabase sq = dop.getWritableDatabase();
sq.beginTransaction();
try {
ContentValues cv = new ContentValues();
cv.put(TableData.TableInfo.COL_ITEMS_ITEMCODE, itemCode);
cv.put(TableData.TableInfo.COL_ITEMS_BRAND, brand);
cv.put(TableData.TableInfo.COL_ITEMS_DESCRIPTION, desc);
sq.insert(TableData.TableInfo.TB_ITEMS, null, cv);
sq.setTransactionSuccessful();
}
catch (Exception e) {

}
finally {
sq.endTransaction();
sq.close();
}
}
}


MainScreen.java



public class MainScreen extends AppCompatActivity {
Context ctx = this;
Button btnSync;

String rowItemURL = "http://192.168.100.118:81/rowItem.php";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);

btnSync = findViewById(R.id.btnSync);
btnSync.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringRequest itemImeiRequest = new StringRequest(Request.Method.POST, rowItemURL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject;
jsonObject = new JSONObject(response);
JSONArray itemArray = jsonObject.getJSONArray("allItems");

for (int i = 0; i < itemArray.length(); i++) {
itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
itemBrand = itemArray.getJSONObject(i).getString("BRAND");
itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

DatabaseOperations dop = new DatabaseOperations(ctx);
dop.insertItems(dop, itemCode, itemBrand, itemDesc);
}

Toast.makeText(ctx, "SYNC ITEMS COMPLETED!", Toast.LENGTH_LONG).show();
lblDebug.setText("SUCCESS!");

}
catch (JSONException e) {
Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
lblDebug.setText(e.getMessage() + "500");
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(ctx, error.getMessage(), Toast.LENGTH_LONG).show();
lblDebug.setText(error.getMessage() + "511");
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
SharedPreferences sharedPreferencesIMEI = getSharedPreferences(IMEI_PREF, MODE_PRIVATE);
myIMEI = sharedPreferencesIMEI.getString(TEXT5, "");

Map<String,String> params = new HashMap<>();
params.put("mySerial", myIMEI);
return params;
}
};
MySingleton.getInstance(MainScreen.this).addToRequestQue(itemImeiRequest);
}
}
}
}


MySingleton.java



public class MySingleton {

private static MySingleton mInstance;
private RequestQueue requestQueue;
private static Context mCtx;

private MySingleton(Context context) {
mCtx = context;
requestQueue = getRequestQueue();
}

public RequestQueue getRequestQueue(){
if(requestQueue==null) {
requestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
}
return requestQueue;
}

public static synchronized MySingleton getInstance(Context context) {
if(mInstance==null) {
mInstance = new MySingleton(context);
}
return mInstance;
}

public<T> void addToRequestQue(Request<T> request) {
requestQueue.add(request);
}
}









share|improve this question











$endgroup$



migrated from stackoverflow.com 2 days ago


This question came from our site for professional and enthusiast programmers.























    3












    $begingroup$


    I'm currently developing an app that requires sending and receiving of data from android studio going to MySQL and then data coming from MySQL will be saved from the SQLite. I need advice on how to make the process faster. Right now I'm inserting 80,000 + rows of data coming from MySQL and then saving it to SQLite and that process lasts around 25-30 minutes.



    rowItem.php



    <?php

    require "init.php";

    $serial = $_POST['mySerial'];

    $sql = "select ITEMCODE, DESCRIPTION, BRAND from items where SERIAL_NO = '" .$serial. "'";
    $result = mysqli_query($con, $sql);

    $data =array();

    while($row = mysqli_fetch_array($result)) {
    $row['ITEMCODE'] = mb_convert_encoding($row['ITEMCODE'], 'UTF-8', 'UTF-8');
    $row['DESCRIPTION'] = mb_convert_encoding($row['DESCRIPTION'], 'UTF-8', 'UTF-8');
    $row['BRAND'] = mb_convert_encoding($row['BRAND'], 'UTF-8', 'UTF-8');
    array_push($data, array('ITEMCODE' => $row['ITEMCODE'], 'DESCRIPTION' => $row['DESCRIPTION'], 'BRAND' => $row['BRAND']));
    }

    $json = json_encode(array("allItems"=>$data));
    echo $json;

    ?>


    DatabaseOperations.java



        public class DatabaseOperations extends SQLiteOpenHelper {
    public static final int dbVersion = 1;

    public String CREATE_ITEMS_TABLE = "CREATE TABLE " + TableData.TableInfo.TB_ITEMS +
    " (" + TableData.TableInfo.COL_ITEMS_ITEMCODE + " VARCHAR(20) PRIMARY KEY NOT NULL, " +
    TableData.TableInfo.COL_ITEMS_DESCRIPTION + " VARCHAR(50), " +
    TableData.TableInfo.COL_ITEMS_BRAND + " VARCHAR(10), " +
    TableData.TableInfo.COL_ITEMS_BARCODE + " VARCHAR(20));";

    public DatabaseOperations(Context context) {
    super(context, TableData.TableInfo.DB_NAME, null, dbVersion);
    }

    @Override
    public void onCreate(SQLiteDatabase sdb) {
    sdb.execSQL(CREATE_ITEMS_TABLE);
    }

    public void insertItems (DatabaseOperations dop,
    String itemCode, String brand, String desc) {
    SQLiteDatabase sq = dop.getWritableDatabase();
    sq.beginTransaction();
    try {
    ContentValues cv = new ContentValues();
    cv.put(TableData.TableInfo.COL_ITEMS_ITEMCODE, itemCode);
    cv.put(TableData.TableInfo.COL_ITEMS_BRAND, brand);
    cv.put(TableData.TableInfo.COL_ITEMS_DESCRIPTION, desc);
    sq.insert(TableData.TableInfo.TB_ITEMS, null, cv);
    sq.setTransactionSuccessful();
    }
    catch (Exception e) {

    }
    finally {
    sq.endTransaction();
    sq.close();
    }
    }
    }


    MainScreen.java



    public class MainScreen extends AppCompatActivity {
    Context ctx = this;
    Button btnSync;

    String rowItemURL = "http://192.168.100.118:81/rowItem.php";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_screen);

    btnSync = findViewById(R.id.btnSync);
    btnSync.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    StringRequest itemImeiRequest = new StringRequest(Request.Method.POST, rowItemURL,
    new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
    try {
    JSONObject jsonObject;
    jsonObject = new JSONObject(response);
    JSONArray itemArray = jsonObject.getJSONArray("allItems");

    for (int i = 0; i < itemArray.length(); i++) {
    itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
    itemBrand = itemArray.getJSONObject(i).getString("BRAND");
    itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

    DatabaseOperations dop = new DatabaseOperations(ctx);
    dop.insertItems(dop, itemCode, itemBrand, itemDesc);
    }

    Toast.makeText(ctx, "SYNC ITEMS COMPLETED!", Toast.LENGTH_LONG).show();
    lblDebug.setText("SUCCESS!");

    }
    catch (JSONException e) {
    Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
    lblDebug.setText(e.getMessage() + "500");
    }
    }
    }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
    Toast.makeText(ctx, error.getMessage(), Toast.LENGTH_LONG).show();
    lblDebug.setText(error.getMessage() + "511");
    }
    }) {
    @Override
    protected Map<String, String> getParams() throws AuthFailureError {
    SharedPreferences sharedPreferencesIMEI = getSharedPreferences(IMEI_PREF, MODE_PRIVATE);
    myIMEI = sharedPreferencesIMEI.getString(TEXT5, "");

    Map<String,String> params = new HashMap<>();
    params.put("mySerial", myIMEI);
    return params;
    }
    };
    MySingleton.getInstance(MainScreen.this).addToRequestQue(itemImeiRequest);
    }
    }
    }
    }


    MySingleton.java



    public class MySingleton {

    private static MySingleton mInstance;
    private RequestQueue requestQueue;
    private static Context mCtx;

    private MySingleton(Context context) {
    mCtx = context;
    requestQueue = getRequestQueue();
    }

    public RequestQueue getRequestQueue(){
    if(requestQueue==null) {
    requestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
    }
    return requestQueue;
    }

    public static synchronized MySingleton getInstance(Context context) {
    if(mInstance==null) {
    mInstance = new MySingleton(context);
    }
    return mInstance;
    }

    public<T> void addToRequestQue(Request<T> request) {
    requestQueue.add(request);
    }
    }









    share|improve this question











    $endgroup$



    migrated from stackoverflow.com 2 days ago


    This question came from our site for professional and enthusiast programmers.





















      3












      3








      3





      $begingroup$


      I'm currently developing an app that requires sending and receiving of data from android studio going to MySQL and then data coming from MySQL will be saved from the SQLite. I need advice on how to make the process faster. Right now I'm inserting 80,000 + rows of data coming from MySQL and then saving it to SQLite and that process lasts around 25-30 minutes.



      rowItem.php



      <?php

      require "init.php";

      $serial = $_POST['mySerial'];

      $sql = "select ITEMCODE, DESCRIPTION, BRAND from items where SERIAL_NO = '" .$serial. "'";
      $result = mysqli_query($con, $sql);

      $data =array();

      while($row = mysqli_fetch_array($result)) {
      $row['ITEMCODE'] = mb_convert_encoding($row['ITEMCODE'], 'UTF-8', 'UTF-8');
      $row['DESCRIPTION'] = mb_convert_encoding($row['DESCRIPTION'], 'UTF-8', 'UTF-8');
      $row['BRAND'] = mb_convert_encoding($row['BRAND'], 'UTF-8', 'UTF-8');
      array_push($data, array('ITEMCODE' => $row['ITEMCODE'], 'DESCRIPTION' => $row['DESCRIPTION'], 'BRAND' => $row['BRAND']));
      }

      $json = json_encode(array("allItems"=>$data));
      echo $json;

      ?>


      DatabaseOperations.java



          public class DatabaseOperations extends SQLiteOpenHelper {
      public static final int dbVersion = 1;

      public String CREATE_ITEMS_TABLE = "CREATE TABLE " + TableData.TableInfo.TB_ITEMS +
      " (" + TableData.TableInfo.COL_ITEMS_ITEMCODE + " VARCHAR(20) PRIMARY KEY NOT NULL, " +
      TableData.TableInfo.COL_ITEMS_DESCRIPTION + " VARCHAR(50), " +
      TableData.TableInfo.COL_ITEMS_BRAND + " VARCHAR(10), " +
      TableData.TableInfo.COL_ITEMS_BARCODE + " VARCHAR(20));";

      public DatabaseOperations(Context context) {
      super(context, TableData.TableInfo.DB_NAME, null, dbVersion);
      }

      @Override
      public void onCreate(SQLiteDatabase sdb) {
      sdb.execSQL(CREATE_ITEMS_TABLE);
      }

      public void insertItems (DatabaseOperations dop,
      String itemCode, String brand, String desc) {
      SQLiteDatabase sq = dop.getWritableDatabase();
      sq.beginTransaction();
      try {
      ContentValues cv = new ContentValues();
      cv.put(TableData.TableInfo.COL_ITEMS_ITEMCODE, itemCode);
      cv.put(TableData.TableInfo.COL_ITEMS_BRAND, brand);
      cv.put(TableData.TableInfo.COL_ITEMS_DESCRIPTION, desc);
      sq.insert(TableData.TableInfo.TB_ITEMS, null, cv);
      sq.setTransactionSuccessful();
      }
      catch (Exception e) {

      }
      finally {
      sq.endTransaction();
      sq.close();
      }
      }
      }


      MainScreen.java



      public class MainScreen extends AppCompatActivity {
      Context ctx = this;
      Button btnSync;

      String rowItemURL = "http://192.168.100.118:81/rowItem.php";

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main_screen);

      btnSync = findViewById(R.id.btnSync);
      btnSync.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      StringRequest itemImeiRequest = new StringRequest(Request.Method.POST, rowItemURL,
      new Response.Listener<String>() {
      @Override
      public void onResponse(String response) {
      try {
      JSONObject jsonObject;
      jsonObject = new JSONObject(response);
      JSONArray itemArray = jsonObject.getJSONArray("allItems");

      for (int i = 0; i < itemArray.length(); i++) {
      itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
      itemBrand = itemArray.getJSONObject(i).getString("BRAND");
      itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

      DatabaseOperations dop = new DatabaseOperations(ctx);
      dop.insertItems(dop, itemCode, itemBrand, itemDesc);
      }

      Toast.makeText(ctx, "SYNC ITEMS COMPLETED!", Toast.LENGTH_LONG).show();
      lblDebug.setText("SUCCESS!");

      }
      catch (JSONException e) {
      Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
      lblDebug.setText(e.getMessage() + "500");
      }
      }
      }, new Response.ErrorListener() {
      @Override
      public void onErrorResponse(VolleyError error) {
      Toast.makeText(ctx, error.getMessage(), Toast.LENGTH_LONG).show();
      lblDebug.setText(error.getMessage() + "511");
      }
      }) {
      @Override
      protected Map<String, String> getParams() throws AuthFailureError {
      SharedPreferences sharedPreferencesIMEI = getSharedPreferences(IMEI_PREF, MODE_PRIVATE);
      myIMEI = sharedPreferencesIMEI.getString(TEXT5, "");

      Map<String,String> params = new HashMap<>();
      params.put("mySerial", myIMEI);
      return params;
      }
      };
      MySingleton.getInstance(MainScreen.this).addToRequestQue(itemImeiRequest);
      }
      }
      }
      }


      MySingleton.java



      public class MySingleton {

      private static MySingleton mInstance;
      private RequestQueue requestQueue;
      private static Context mCtx;

      private MySingleton(Context context) {
      mCtx = context;
      requestQueue = getRequestQueue();
      }

      public RequestQueue getRequestQueue(){
      if(requestQueue==null) {
      requestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
      }
      return requestQueue;
      }

      public static synchronized MySingleton getInstance(Context context) {
      if(mInstance==null) {
      mInstance = new MySingleton(context);
      }
      return mInstance;
      }

      public<T> void addToRequestQue(Request<T> request) {
      requestQueue.add(request);
      }
      }









      share|improve this question











      $endgroup$




      I'm currently developing an app that requires sending and receiving of data from android studio going to MySQL and then data coming from MySQL will be saved from the SQLite. I need advice on how to make the process faster. Right now I'm inserting 80,000 + rows of data coming from MySQL and then saving it to SQLite and that process lasts around 25-30 minutes.



      rowItem.php



      <?php

      require "init.php";

      $serial = $_POST['mySerial'];

      $sql = "select ITEMCODE, DESCRIPTION, BRAND from items where SERIAL_NO = '" .$serial. "'";
      $result = mysqli_query($con, $sql);

      $data =array();

      while($row = mysqli_fetch_array($result)) {
      $row['ITEMCODE'] = mb_convert_encoding($row['ITEMCODE'], 'UTF-8', 'UTF-8');
      $row['DESCRIPTION'] = mb_convert_encoding($row['DESCRIPTION'], 'UTF-8', 'UTF-8');
      $row['BRAND'] = mb_convert_encoding($row['BRAND'], 'UTF-8', 'UTF-8');
      array_push($data, array('ITEMCODE' => $row['ITEMCODE'], 'DESCRIPTION' => $row['DESCRIPTION'], 'BRAND' => $row['BRAND']));
      }

      $json = json_encode(array("allItems"=>$data));
      echo $json;

      ?>


      DatabaseOperations.java



          public class DatabaseOperations extends SQLiteOpenHelper {
      public static final int dbVersion = 1;

      public String CREATE_ITEMS_TABLE = "CREATE TABLE " + TableData.TableInfo.TB_ITEMS +
      " (" + TableData.TableInfo.COL_ITEMS_ITEMCODE + " VARCHAR(20) PRIMARY KEY NOT NULL, " +
      TableData.TableInfo.COL_ITEMS_DESCRIPTION + " VARCHAR(50), " +
      TableData.TableInfo.COL_ITEMS_BRAND + " VARCHAR(10), " +
      TableData.TableInfo.COL_ITEMS_BARCODE + " VARCHAR(20));";

      public DatabaseOperations(Context context) {
      super(context, TableData.TableInfo.DB_NAME, null, dbVersion);
      }

      @Override
      public void onCreate(SQLiteDatabase sdb) {
      sdb.execSQL(CREATE_ITEMS_TABLE);
      }

      public void insertItems (DatabaseOperations dop,
      String itemCode, String brand, String desc) {
      SQLiteDatabase sq = dop.getWritableDatabase();
      sq.beginTransaction();
      try {
      ContentValues cv = new ContentValues();
      cv.put(TableData.TableInfo.COL_ITEMS_ITEMCODE, itemCode);
      cv.put(TableData.TableInfo.COL_ITEMS_BRAND, brand);
      cv.put(TableData.TableInfo.COL_ITEMS_DESCRIPTION, desc);
      sq.insert(TableData.TableInfo.TB_ITEMS, null, cv);
      sq.setTransactionSuccessful();
      }
      catch (Exception e) {

      }
      finally {
      sq.endTransaction();
      sq.close();
      }
      }
      }


      MainScreen.java



      public class MainScreen extends AppCompatActivity {
      Context ctx = this;
      Button btnSync;

      String rowItemURL = "http://192.168.100.118:81/rowItem.php";

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main_screen);

      btnSync = findViewById(R.id.btnSync);
      btnSync.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      StringRequest itemImeiRequest = new StringRequest(Request.Method.POST, rowItemURL,
      new Response.Listener<String>() {
      @Override
      public void onResponse(String response) {
      try {
      JSONObject jsonObject;
      jsonObject = new JSONObject(response);
      JSONArray itemArray = jsonObject.getJSONArray("allItems");

      for (int i = 0; i < itemArray.length(); i++) {
      itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
      itemBrand = itemArray.getJSONObject(i).getString("BRAND");
      itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

      DatabaseOperations dop = new DatabaseOperations(ctx);
      dop.insertItems(dop, itemCode, itemBrand, itemDesc);
      }

      Toast.makeText(ctx, "SYNC ITEMS COMPLETED!", Toast.LENGTH_LONG).show();
      lblDebug.setText("SUCCESS!");

      }
      catch (JSONException e) {
      Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
      lblDebug.setText(e.getMessage() + "500");
      }
      }
      }, new Response.ErrorListener() {
      @Override
      public void onErrorResponse(VolleyError error) {
      Toast.makeText(ctx, error.getMessage(), Toast.LENGTH_LONG).show();
      lblDebug.setText(error.getMessage() + "511");
      }
      }) {
      @Override
      protected Map<String, String> getParams() throws AuthFailureError {
      SharedPreferences sharedPreferencesIMEI = getSharedPreferences(IMEI_PREF, MODE_PRIVATE);
      myIMEI = sharedPreferencesIMEI.getString(TEXT5, "");

      Map<String,String> params = new HashMap<>();
      params.put("mySerial", myIMEI);
      return params;
      }
      };
      MySingleton.getInstance(MainScreen.this).addToRequestQue(itemImeiRequest);
      }
      }
      }
      }


      MySingleton.java



      public class MySingleton {

      private static MySingleton mInstance;
      private RequestQueue requestQueue;
      private static Context mCtx;

      private MySingleton(Context context) {
      mCtx = context;
      requestQueue = getRequestQueue();
      }

      public RequestQueue getRequestQueue(){
      if(requestQueue==null) {
      requestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
      }
      return requestQueue;
      }

      public static synchronized MySingleton getInstance(Context context) {
      if(mInstance==null) {
      mInstance = new MySingleton(context);
      }
      return mInstance;
      }

      public<T> void addToRequestQue(Request<T> request) {
      requestQueue.add(request);
      }
      }






      java php android mysql sqlite






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      Jamal

      30.3k11119227




      30.3k11119227










      asked 2 days ago









      aria mossararia mossar

      285




      285




      migrated from stackoverflow.com 2 days ago


      This question came from our site for professional and enthusiast programmers.









      migrated from stackoverflow.com 2 days ago


      This question came from our site for professional and enthusiast programmers.
























          1 Answer
          1






          active

          oldest

          votes


















          3












          $begingroup$

          You are using a transaction per insert statement, that will basically do nothing as a single statement on it's own is effectively a transaction.



          You want to perform the loop within a single transaction so that the disk is written just the once, rather than for every insert.



          I'd suggest changing :-



                                      for (int i = 0; i < itemArray.length(); i++) {
          itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
          itemBrand = itemArray.getJSONObject(i).getString("BRAND");
          itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

          DatabaseOperations dop = new DatabaseOperations(ctx);
          dop.insertItems(dop, itemCode, itemBrand, itemDesc);
          }


          to :-



                                  DatabaseOperations dop = new DatabaseOperations(ctx);
          dop.getWritableDatabase().beginTransaction();
          for (int i = 0; i < itemArray.length(); i++) {
          itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
          itemBrand = itemArray.getJSONObject(i).getString("BRAND");
          itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

          dop.insertItems(dop, itemCode, itemBrand, itemDesc);
          }
          dop.setTransactionSuccessful();
          dop.endTransaction();


          Along with changing the insertItems method to :-



              public void insertItems (DatabaseOperations dop,
          String itemCode, String brand, String desc) {
          SQLiteDatabase sq = dop.getWritableDatabase();

          ContentValues cv = new ContentValues();
          cv.put(TableData.TableInfo.COL_ITEMS_ITEMCODE, itemCode);
          cv.put(TableData.TableInfo.COL_ITEMS_BRAND, brand);
          cv.put(TableData.TableInfo.COL_ITEMS_DESCRIPTION, desc);
          sq.insert(TableData.TableInfo.TB_ITEMS, null, cv);
          }



          • Note this is in-principle code, it has not been run or tested and may therefore contain some errors.


          • Note in regard to SQL Injection, the Android convenience methods, such as insert do provide protection against SQL injection as the values extracted from the ContentValues are appropriately enclosed when the underlying SQL is built by the methods.







          share|improve this answer











          $endgroup$













            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "196"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214379%2fsending-and-receiving-of-json-data-to-and-from-android-studio%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3












            $begingroup$

            You are using a transaction per insert statement, that will basically do nothing as a single statement on it's own is effectively a transaction.



            You want to perform the loop within a single transaction so that the disk is written just the once, rather than for every insert.



            I'd suggest changing :-



                                        for (int i = 0; i < itemArray.length(); i++) {
            itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
            itemBrand = itemArray.getJSONObject(i).getString("BRAND");
            itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

            DatabaseOperations dop = new DatabaseOperations(ctx);
            dop.insertItems(dop, itemCode, itemBrand, itemDesc);
            }


            to :-



                                    DatabaseOperations dop = new DatabaseOperations(ctx);
            dop.getWritableDatabase().beginTransaction();
            for (int i = 0; i < itemArray.length(); i++) {
            itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
            itemBrand = itemArray.getJSONObject(i).getString("BRAND");
            itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

            dop.insertItems(dop, itemCode, itemBrand, itemDesc);
            }
            dop.setTransactionSuccessful();
            dop.endTransaction();


            Along with changing the insertItems method to :-



                public void insertItems (DatabaseOperations dop,
            String itemCode, String brand, String desc) {
            SQLiteDatabase sq = dop.getWritableDatabase();

            ContentValues cv = new ContentValues();
            cv.put(TableData.TableInfo.COL_ITEMS_ITEMCODE, itemCode);
            cv.put(TableData.TableInfo.COL_ITEMS_BRAND, brand);
            cv.put(TableData.TableInfo.COL_ITEMS_DESCRIPTION, desc);
            sq.insert(TableData.TableInfo.TB_ITEMS, null, cv);
            }



            • Note this is in-principle code, it has not been run or tested and may therefore contain some errors.


            • Note in regard to SQL Injection, the Android convenience methods, such as insert do provide protection against SQL injection as the values extracted from the ContentValues are appropriately enclosed when the underlying SQL is built by the methods.







            share|improve this answer











            $endgroup$


















              3












              $begingroup$

              You are using a transaction per insert statement, that will basically do nothing as a single statement on it's own is effectively a transaction.



              You want to perform the loop within a single transaction so that the disk is written just the once, rather than for every insert.



              I'd suggest changing :-



                                          for (int i = 0; i < itemArray.length(); i++) {
              itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
              itemBrand = itemArray.getJSONObject(i).getString("BRAND");
              itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

              DatabaseOperations dop = new DatabaseOperations(ctx);
              dop.insertItems(dop, itemCode, itemBrand, itemDesc);
              }


              to :-



                                      DatabaseOperations dop = new DatabaseOperations(ctx);
              dop.getWritableDatabase().beginTransaction();
              for (int i = 0; i < itemArray.length(); i++) {
              itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
              itemBrand = itemArray.getJSONObject(i).getString("BRAND");
              itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

              dop.insertItems(dop, itemCode, itemBrand, itemDesc);
              }
              dop.setTransactionSuccessful();
              dop.endTransaction();


              Along with changing the insertItems method to :-



                  public void insertItems (DatabaseOperations dop,
              String itemCode, String brand, String desc) {
              SQLiteDatabase sq = dop.getWritableDatabase();

              ContentValues cv = new ContentValues();
              cv.put(TableData.TableInfo.COL_ITEMS_ITEMCODE, itemCode);
              cv.put(TableData.TableInfo.COL_ITEMS_BRAND, brand);
              cv.put(TableData.TableInfo.COL_ITEMS_DESCRIPTION, desc);
              sq.insert(TableData.TableInfo.TB_ITEMS, null, cv);
              }



              • Note this is in-principle code, it has not been run or tested and may therefore contain some errors.


              • Note in regard to SQL Injection, the Android convenience methods, such as insert do provide protection against SQL injection as the values extracted from the ContentValues are appropriately enclosed when the underlying SQL is built by the methods.







              share|improve this answer











              $endgroup$
















                3












                3








                3





                $begingroup$

                You are using a transaction per insert statement, that will basically do nothing as a single statement on it's own is effectively a transaction.



                You want to perform the loop within a single transaction so that the disk is written just the once, rather than for every insert.



                I'd suggest changing :-



                                            for (int i = 0; i < itemArray.length(); i++) {
                itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
                itemBrand = itemArray.getJSONObject(i).getString("BRAND");
                itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

                DatabaseOperations dop = new DatabaseOperations(ctx);
                dop.insertItems(dop, itemCode, itemBrand, itemDesc);
                }


                to :-



                                        DatabaseOperations dop = new DatabaseOperations(ctx);
                dop.getWritableDatabase().beginTransaction();
                for (int i = 0; i < itemArray.length(); i++) {
                itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
                itemBrand = itemArray.getJSONObject(i).getString("BRAND");
                itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

                dop.insertItems(dop, itemCode, itemBrand, itemDesc);
                }
                dop.setTransactionSuccessful();
                dop.endTransaction();


                Along with changing the insertItems method to :-



                    public void insertItems (DatabaseOperations dop,
                String itemCode, String brand, String desc) {
                SQLiteDatabase sq = dop.getWritableDatabase();

                ContentValues cv = new ContentValues();
                cv.put(TableData.TableInfo.COL_ITEMS_ITEMCODE, itemCode);
                cv.put(TableData.TableInfo.COL_ITEMS_BRAND, brand);
                cv.put(TableData.TableInfo.COL_ITEMS_DESCRIPTION, desc);
                sq.insert(TableData.TableInfo.TB_ITEMS, null, cv);
                }



                • Note this is in-principle code, it has not been run or tested and may therefore contain some errors.


                • Note in regard to SQL Injection, the Android convenience methods, such as insert do provide protection against SQL injection as the values extracted from the ContentValues are appropriately enclosed when the underlying SQL is built by the methods.







                share|improve this answer











                $endgroup$



                You are using a transaction per insert statement, that will basically do nothing as a single statement on it's own is effectively a transaction.



                You want to perform the loop within a single transaction so that the disk is written just the once, rather than for every insert.



                I'd suggest changing :-



                                            for (int i = 0; i < itemArray.length(); i++) {
                itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
                itemBrand = itemArray.getJSONObject(i).getString("BRAND");
                itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

                DatabaseOperations dop = new DatabaseOperations(ctx);
                dop.insertItems(dop, itemCode, itemBrand, itemDesc);
                }


                to :-



                                        DatabaseOperations dop = new DatabaseOperations(ctx);
                dop.getWritableDatabase().beginTransaction();
                for (int i = 0; i < itemArray.length(); i++) {
                itemCode = itemArray.getJSONObject(i).getString("ITEMCODE");
                itemBrand = itemArray.getJSONObject(i).getString("BRAND");
                itemDesc = itemArray.getJSONObject(i).getString("DESCRIPTION");

                dop.insertItems(dop, itemCode, itemBrand, itemDesc);
                }
                dop.setTransactionSuccessful();
                dop.endTransaction();


                Along with changing the insertItems method to :-



                    public void insertItems (DatabaseOperations dop,
                String itemCode, String brand, String desc) {
                SQLiteDatabase sq = dop.getWritableDatabase();

                ContentValues cv = new ContentValues();
                cv.put(TableData.TableInfo.COL_ITEMS_ITEMCODE, itemCode);
                cv.put(TableData.TableInfo.COL_ITEMS_BRAND, brand);
                cv.put(TableData.TableInfo.COL_ITEMS_DESCRIPTION, desc);
                sq.insert(TableData.TableInfo.TB_ITEMS, null, cv);
                }



                • Note this is in-principle code, it has not been run or tested and may therefore contain some errors.


                • Note in regard to SQL Injection, the Android convenience methods, such as insert do provide protection against SQL injection as the values extracted from the ContentValues are appropriately enclosed when the underlying SQL is built by the methods.








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 2 days ago

























                answered 2 days ago









                MikeTMikeT

                1465




                1465






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Code Review Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214379%2fsending-and-receiving-of-json-data-to-and-from-android-studio%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Fairchild Swearingen Metro Inhaltsverzeichnis Geschichte | Innenausstattung | Nutzung | Zwischenfälle...

                    Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...

                    Marineschifffahrtleitung Inhaltsverzeichnis Geschichte | Heutige Organisation der NATO | Nationale und...