I'm trying to retrieve the cloud contacts of the user during the Log-in and save them locally in the SQLite, everything is fine until i must write the info into the db, but using a phone with API 18 (4.3) seems that some of the values of the dedicated array are lost, this doesn't happen with another phone with API 22 (5.1.1). I'm trying to figure out the reason of this behavior but after some test i don't know what else do. However, i notice a strange thing, when i start the app using API 18 i got some strange warning in the Android Studio Log, i've made some research but i don't know if it's relevant.
Code in the activity:
DatabaseNumbersHandler dbn = new DatabaseNumbersHandler(getApplicationContext());
Integer jsonLen = json.length();
String[][] id = new String[jsonLen][4];
String[][] number = new String[jsonLen][4];
String[][] title = new String[jsonLen][4];
String[][] description = new String[jsonLen][4];
String[][] time_creation = new String[jsonLen][4];
Integer stop = 0;
Integer iter_position = 0;
for (int i = 0; i < jsonLen; i++) {
Log.v("ITER POS", String.valueOf(iter_position));
JSONObject object = json.optJSONObject(i);
Iterator<String> iterator = object.keys();
while (iterator.hasNext()) {
try {
String currentKey = iterator.next();
String currentValue = object.getString(currentKey);
// If the key name is not numerical go on
if (!currentKey.matches("[-+]?\\d*\\.?\\d+")) {
Log.v("KEY_CLEAN", currentKey);
// If an "error" key exists show the alert and stop the db writing
if (currentKey.matches(KEY_ERROR)) {
if (Integer.parseInt(currentValue) == 1){
// If no number exists
final String no_contacts = getResources().getString(R.string.no_contacts_imported);
Toast.makeText(getApplicationContext(),
no_contacts, Toast.LENGTH_LONG).show();
stop = 1;
break;
} else if (Integer.parseInt(currentValue) == 2) {
// If the numbers are not imported due to an error
final String contacts_error = getResources().getString(R.string.error_contacts_not_imported);
Toast.makeText(getApplicationContext(),
contacts_error, Toast.LENGTH_LONG).show();
stop = 1;
break;
} else {
// Undefined error
final String undefined_error = getResources().getString(R.string.undefined_error);
Toast.makeText(getApplicationContext(),
undefined_error, Toast.LENGTH_LONG).show();
stop = 1;
break;
}
} else {
switch(currentKey){
case "id":
id[i][iter_position] = currentValue;
Log.v("ID", id[i][iter_position]);
break;
case "smart_number":
smart_number[i][iter_position] = currentValue;
Log.v("NUMBER", number[i][iter_position]);
break;
case "title":
title[i][iter_position] = currentValue;
Log.v("TITLE", title[i][iter_position]);
break;
case "description":
description[i][iter_position] = currentValue;
Log.v("DESC", description[i][iter_position]);
break;
case "time_creation":
time_creation[i][iter_position] = currentValue;
Log.v("TIME", time_creation[i][iter_position]);
iter_position++;
break;
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
if(stop.equals(0)) {
for (int i = 0; i < jsonLen; i++) {
Log.v("WRITE ID", String.valueOf(id[i][i]));
Log.v("WRITE NUMBER", String.valueOf(number[i][i]));
Log.v("WRITE TITLE", String.valueOf(title[i][i]));
Log.v("WRITE DESC", String.valueOf(description[i][i]));
Log.v("WRITE TIME", String.valueOf(time_creation[i][i]));
dbn.addNumber(id[i][i], user_id_get, number[i][i], title[i][i], description[i][i], time_creation[i][i]);
}
}
Generated log with API 18 (Android 4.3)
Note: The first row is the json array returned from the cloud
02-29 14:55:57.049 2847-7742/com.myapp E/JSON: [{"id":2,"0":2,"number":3384729034,"1":3384729034,"title":"Mark","2":"Mark","description":"friend","3":"friend","time_creation":1449830672,"4":1449830672},{"id":3,"0":3,"number":3497812429,"1":3497812429,"title":"Erik","2":"Erik","description":"brother","3":"brother","time_creation":1455030339,"4":1455030339}]
02-29 14:55:57.064 2847-2847/com.myapp V/ITER POS: 0
02-29 14:55:57.069 2847-2847/com.myapp V/KEY_CLEAN: id
02-29 14:55:57.069 2847-2847/com.myapp V/ID: 2
02-29 14:55:57.074 2847-2847/com.myapp V/KEY_CLEAN: title
02-29 14:55:57.074 2847-2847/com.myapp V/TITLE: Mark
02-29 14:55:57.074 2847-2847/com.myapp V/KEY_CLEAN: time_creation
02-29 14:55:57.074 2847-2847/com.myapp V/TIME: 1449830672
02-29 14:55:57.079 2847-2847/com.myapp V/KEY_CLEAN: number
02-29 14:55:57.079 2847-2847/com.myapp V/NUMBER: 3384729034
02-29 14:55:57.079 2847-2847/com.myapp V/KEY_CLEAN: description
02-29 14:55:57.079 2847-2847/com.myapp V/DESC: friend
02-29 14:55:57.079 2847-2847/com.myapp V/ITER POS: 1
02-29 14:55:57.084 2847-2847/com.myapp V/KEY_CLEAN: id
02-29 14:55:57.084 2847-2847/com.myapp V/ID: 3
02-29 14:55:57.084 2847-2847/com.myapp V/KEY_CLEAN: title
02-29 14:55:57.084 2847-2847/com.myapp V/TITLE: Erik
02-29 14:55:57.089 2847-2847/com.myapp V/KEY_CLEAN: time_creation
02-29 14:55:57.089 2847-2847/com.myapp V/TIME: 1455030339
02-29 14:55:57.089 2847-2847/com.myapp V/KEY_CLEAN: number
02-29 14:55:57.089 2847-2847/com.myapp V/NUMBER: 3497812429
02-29 14:55:57.089 2847-2847/com.myapp V/KEY_CLEAN: description
02-29 14:55:57.094 2847-2847/com.myapp V/DESC: brother
02-29 14:55:57.094 2847-2847/com.myapp V/WRITE ID: 2
02-29 14:55:57.094 2847-2847/com.myapp V/WRITE NUMBER: null
02-29 14:55:57.094 2847-2847/com.myapp V/WRITE TITLE: Mark
02-29 14:55:57.094 2847-2847/com.myapp V/WRITE DESC: null
02-29 14:55:57.094 2847-2847/com.myapp V/WRITE TIME: 1449830672
02-29 14:55:57.104 2847-2847/com.myapp V/WRITE ID: 3
02-29 14:55:57.104 2847-2847/com.myapp V/WRITE NUMBER: null
02-29 14:55:57.104 2847-2847/com.myapp V/WRITE TITLE: Erik
02-29 14:55:57.104 2847-2847/com.myapp V/WRITE DESC: null
02-29 14:55:57.104 2847-2847/com.myapp V/WRITE TIME: 1455030339
Generated log with API 22 (Android 5.1)
Note: The first row is the json array returned from the cloud
02-29 15:05:10.081 23832-24626/com.myapp E/JSON: [{"id":2,"0":2,"number":3384729034,"1":3384729034,"title":"Mark","2":"Mark","description":"friend","3":"friend","time_creation":1449830672,"4":1449830672},{"id":3,"0":3,"number":3497812429,"1":3497812429,"title":"Erik","2":"Erik","description":"brother","3":"brother","time_creation":1455030339,"4":1455030339}]
02-29 15:05:10.081 23832-23832/com.myapp V/ITER POS: 0
02-29 15:05:10.081 23832-23832/com.myapp V/KEY_CLEAN: id
02-29 15:05:10.081 23832-23832/com.myapp V/ID: 2
02-29 15:05:10.081 23832-23832/com.myapp V/KEY_CLEAN: number
02-29 15:05:10.081 23832-23832/com.myapp V/NUMBER: 3384729034
02-29 15:05:10.081 23832-23832/com.myapp V/KEY_CLEAN: title
02-29 15:05:10.081 23832-23832/com.myapp V/TITLE: Mark
02-29 15:05:10.091 23832-23832/com.myapp V/KEY_CLEAN: description
02-29 15:05:10.091 23832-23832/com.myapp V/DESC: friend
02-29 15:05:10.091 23832-23832/com.myapp V/KEY_CLEAN: time_creation
02-29 15:05:10.091 23832-23832/com.myapp V/TIME: 1449830672
02-29 15:05:10.091 23832-23832/com.myapp V/ITER POS: 1
02-29 15:05:10.091 23832-23832/com.myapp V/KEY_CLEAN: id
02-29 15:05:10.091 23832-23832/com.myapp V/ID: 3
02-29 15:05:10.091 23832-23832/com.myapp V/KEY_CLEAN: number
02-29 15:05:10.091 23832-23832/com.myapp V/NUMBER: 3497812429
02-29 15:05:10.091 23832-23832/com.myapp V/KEY_CLEAN: title
02-29 15:05:10.091 23832-23832/com.myapp V/TITLE: Erik
02-29 15:05:10.101 23832-23832/com.myapp V/KEY_CLEAN: description
02-29 15:05:10.101 23832-23832/com.myapp V/DESC: brother
02-29 15:05:10.101 23832-23832/com.myapp V/KEY_CLEAN: time_creation
02-29 15:05:10.101 23832-23832/com.myapp V/TIME: 1455030339
02-29 15:05:10.101 23832-23832/com.myapp V/WRITE ID: 2
02-29 15:05:10.101 23832-23832/com.myapp V/WRITE NUMBER: 3384729034
02-29 15:05:10.101 23832-23832/com.myapp V/WRITE TITLE: Mark
02-29 15:05:10.101 23832-23832/com.myapp V/WRITE DESC: friend
02-29 15:05:10.101 23832-23832/com.myapp V/WRITE TIME: 1449830672
02-29 15:05:10.111 23832-23832/com.myapp V/WRITE ID: 3
02-29 15:05:10.111 23832-23832/com.myapp V/WRITE NUMBER: 3497812429
02-29 15:05:10.111 23832-23832/com.myapp V/WRITE TITLE: Erik
02-29 15:05:10.111 23832-23832/com.myapp V/WRITE DESC: brother
02-29 15:05:10.111 23832-23832/com.myapp V/WRITE TIME: 1455030339
As you can see the array values of "number" and "description" just before the db writing are null with API 18, instead are correct with API 22
The strange warnings that i noticed when i start the app with API 18 are the following:
02-29 14:50:57.264 2847-2847/? D/dalvikvm: Late-enabling CheckJNI
02-29 14:50:57.469 2847-2847/com.myapp W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
02-29 14:50:57.469 2847-2847/com.myapp I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
02-29 14:50:57.469 2847-2847/com.myapp W/dalvikvm: VFY: unable to resolve interface method 18175: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
02-29 14:50:57.469 2847-2847/com.myapp D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
02-29 14:50:57.469 2847-2847/com.myapp I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
02-29 14:50:57.474 2847-2847/com.myapp W/dalvikvm: VFY: unable to resolve interface method 18179: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
02-29 14:50:57.474 2847-2847/com.myapp D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
02-29 14:50:57.519 2847-2847/com.myapp I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
02-29 14:50:57.519 2847-2847/com.myapp W/dalvikvm: VFY: unable to resolve virtual method 490: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
02-29 14:50:57.519 2847-2847/com.myapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
02-29 14:50:57.524 2847-2847/com.myapp I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
02-29 14:50:57.524 2847-2847/com.myapp W/dalvikvm: VFY: unable to resolve virtual method 512: Landroid/content/res/TypedArray;.getType (I)I
02-29 14:50:57.524 2847-2847/com.myapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
02-29 14:50:57.564 2847-2847/com.myapp I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable
02-29 14:50:57.564 2847-2847/com.myapp W/dalvikvm: VFY: unable to resolve virtual method 453: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
02-29 14:50:57.564 2847-2847/com.myapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
02-29 14:50:57.564 2847-2847/com.myapp I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity
02-29 14:50:57.564 2847-2847/com.myapp W/dalvikvm: VFY: unable to resolve virtual method 455: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
02-29 14:50:57.564 2847-2847/com.myapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
02-29 14:50:57.659 2847-2847/com.myapp D/libEGL: loaded /system/lib/egl/libEGL_mali.so
02-29 14:50:57.664 2847-2847/com.myapp D/libEGL: loaded /system/lib/egl/libGLESv1_CM_mali.so
02-29 14:50:57.669 2847-2847/com.myapp D/libEGL: loaded /system/lib/egl/libGLESv2_mali.so
02-29 14:50:57.729 2847-2847/com.myapp D/OpenGLRenderer: Enabling debug mode 0