android - MvvmCross ViewModel Life Cycle -
according information can find, mvvmcross viewmodel life cycle
construction - using ioc dependency injection
init() - initialisation of navigation parameters
reloadstate() - rehydration after tombstoning
start() - called when initialisation , rehydration complete
i have implemented mine follows:
public async task init(guid id) { await mps_mobile_driver.droid.datamodel.shipmentdatasource.getshipmentinventory(id); shipmentinventory = shipmentdatasource.currinventory; shipmentlots = await mps_mobile_driver.droid.datamodel.shipmentdatasource.getshipmentlotlist((int)shipmentinventory.idno, (short)shipmentinventory.idsub); inv_damagelist = await listdatasource.getinv_damage(); } protected override void savestatetobundle(imvxbundle bundle) { base.savestatetobundle(bundle); bundle.data["shipmentinventory"] = stringserializer.serializeobject(shipmentinventory); bundle.data["shipmentlots"] = stringserializer.serializeobject(shipmentlots); bundle.data["inv_damagelist"] = stringserializer.serializeobject(inv_damagelist); } protected override void reloadfrombundle(imvxbundle state) { base.reloadfrombundle(state); shipmentinventory = stringserializer.deserializeobject<shipmentinventory>(state.data["shipmentinventory"]); shipmentlots = stringserializer.deserializeobject<shipmentlotlist>(state.data["shipmentlots"]); inv_damagelist = stringserializer.deserializeobject<inv_damagelist>(state.data["inv_damagelist"]); state.data.clear(); } first off, can't seem emulator destroy activity when hit home key though have option checked. activity seems hang around in background anyway.
that being said, when hit home key, calls savestatetobundle. never seems call reloadfrombundle. makes hard test going on. fear according life cycle, if app recover tombstone, call init before calls reloadfrombundle. since init preferred way pass parameter viewmodel, makes sense should use parameter initialize data. if after happens, calls reloadfrombundle, overwrite data initialized in init. fine inefficient. there way know in init if viewmodel being created due new navigation or if recovering tombstone?
thanks this.
jim
i have same issue reloadfrombundle(imvxbundle state), never called. "savestate" pattern seems work.
i can answer second question though:
you shouldn't use init load data. should use pass ids of data retrieved. "loading" phase should happen in start method.
Comments
Post a Comment