-1

I launch an activity passing a parseobject to next activity

In next activity i make a query and save the list of objects as class field variable. I change some fields of the objects from query result. eg object.putint("abc",122); // I change it from 100 to 122

I DONT call save() or any similar method on these modified objects.

Now i finish the second activity with back button and go back to first activity.

I again launch the second activity as before

The query is made and list of objects is fetched. Not the returned objects have different values as of server. object.getInt("abc") returns 122, not 100 100 is expected value as new query has been made on activity created and the modified parseobject from last time was not saved. But the modified value of parseobject is still saved locally even after activity destroyed.

To verify in ondestroy of second activity i set the object value to 9999 and after relaunching that activity and making the query the value returned in network log (100) does not match value printed later via log.

Field is not static and localdatastore is not in use.

EDIT:

Activity 1:

...
intent.putExtra("obj",myOrderParseObject);
startActivity...


Activity 2:

...
somequery.whereEqualTo("someField",getIntent.get...("obj");
List<Type2ParseObject> result = somequery.find();
...

result.get(0).getInt("myvalue") //return 100
result.get(0).put("myvalue",50)
finish();

Back to Activity 1:
...
intent.putExtra("obj",myOrderParseObject);
startActivity...    //Again start activity 

Activity 2:

//Again the same query
...
somequery.whereEqualTo("someField",getIntent.get...("obj");
List<Type2ParseObject> result = somequery.find();
...

result.get(0).getInt("myvalue") //returns 50 not 100!!!

I expected 100 as it is original server value but i got 50 which i put last time but not called any save() method.

How did the value persisted even after activity crash>  
Manuel
  • 14,274
  • 6
  • 57
  • 130
Omkar T
  • 755
  • 8
  • 19

1 Answers1

-1

After some research I found out that If LocalDataStore is enabled and an item is pinned. Then if the item is modified with put methods like item.put(somefield,1020); then item.save() is not required.

The pinned item is updated automatically without calling save or pin method again on it.

In my case in activity 2 i was modifying the object but not calling save() or pin() but still the item value was updated and persisted in localDataStore.

This beheviour is problematic because sometimes you modify the ParseObjects and call save() when user hits the confirm button. If the button is not clicked and app closed,then the changes are not expected to be saved but here they are saved on every put() call.

That's my experience with LocalDataStore.

Solutions for me were: 1. instead of

   object.put("price",newValue);

i use

   object.put("temp_price",newValue);

and later when user clicks confirm

instead of

   object.save() //Saving the object on server,when online

i use

 object.put("price",object.getInt("temp_price"))
   object.save()
Omkar T
  • 755
  • 8
  • 19