Good, this is going to be something extensive but here goes, my problem is the following. I have two arrays that send an Activity to another via Intent
. In the next activity I receive them as Strings, they can also be empty "[]", then I convert them into JSONArray
in this way:
//Convertir String a Array - Esto se encuentra en el OnCreate
try {
arrayImagenes = new JSONArray(imagenes); // String imagenes
arrayNotas = new JSONArray(notas); // String notas
}
catch (JSONException e) {
e.printStackTrace();
}
Here I also have two buttons, two Adapter Classes (corresponding to each Array) and a ListView where I show the items of each Array.
The next thing I do is start listing the objects in the array in the ListView
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
...
// Se muestra por defecto la lista 'Notas' al iniciar la Actividad
if(arrayNotas == null || arrayNotas.length() == 0) {
mensajeError.setVisibility(View.VISIBLE);
lista.setVisibility(View.GONE);
}
else {
lista.setAdapter(new NotasAdapter(context, R.layout.actividad_itemlist, arrayNotas));
lista.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
Then I have the buttons with which I show the list that I want to see in this way:
public void buttons() {
listarNotas.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(arrayNotas == null || arrayNotas.length() == 0) {
mensajeError.setVisibility(View.VISIBLE);
lista.setVisibility(View.GONE);
}
else {
lista.setAdapter(new NotasAdapter(context, R.layout.actividad_itemlist, arrayNotas));
lista.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
}
});
listarFotos.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(arrayImagenes == null || arrayImagenes.length() == 0) {
mensajeError.setVisibility(View.VISIBLE);
lista.setVisibility(View.GONE);
}
else {
lista.setAdapter(new ImagenesAdapter(context, R.layout.actividad_itemlist, arrayImagenes));
lista.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
}
});
}
When carrying out the processes of sending Note or Image Upload using an AsyncTask, I receive the arrays again but with an object loaded based on the process performed as follows:
{
"id": 8,
"mes": "Julio",
...
"notas": [
{
"id": 37,
"nota": "Hola Mundo",
...
...
}
"imagenes": [
// Vacia
]
In the onPostExecute of each process, I start the same Activity via Intent, sending back the Notes and Images arrays to "Reload" the View and display the added items.
The sending of notes works well, in fact after doing that process it shows me a new item in the list of Notes, if I press the List button, it returns empty to me obviously and now the problem is that if I press the button again to listNotes this also returns empty.
I checked if the result of the AsyncTask returned an item in the array of notes and is indeed there, then why it disappears? It should also be noted that if I upload an image first and not a note, that new item is not displayed in the Images list but it appears in the AsyncTask result.