android - How to handle preliminary models while waiting for server responses? -


in android app work on, models stored globally , activities notified changes created, updated , deleted models. according callbacks called after receiving server response.

there main activity lists models , activity create new ones. there, user can fill out couple of fields , click on save. triggers server request create new model. after getting response, validated model server added global collection , notification callbacks executed. problem while waiting response.

  1. we block user interface show spinner. that's not responsive , results in poor user experience.
  2. we add local preliminary model , add global collection , trigger notification callbacks. allows main activity add list. after response, update or delete preliminary model, depending on success or failure of request. however, preliminary model doesn't have id yet, hard find in collection updating or removal.
  3. building on approach, assign random preliminary id preliminary model. however, if user interacts new model, create ill-defined requests use wrong preliminary id.

how can handle preliminary models in multiple activities while waiting server responses in clear , responsive way?

the best answer in 2 let client create id. don't use consecutive ids sequence. use random uuid of 128 bits. client can randomly create new id , have virtually 0 chance of failing.

if virtually 0 isn't enough, have client create temporary id. have server either accept id, or send down response both temporary , permanent id, client can remap temporary id new value. requests went out between creation on client , server either resent client or remapped server.

although really- 128 bit random id has little chance of ever hitting dupe don't need worry it. on earth create billion models , have less 1 in 1 billion chance of collision next time tried.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -