When to save the state of the application for the tomb?

I was wondering when it is more convenient to save the model for viewing individual pages.

I see two possibilities:

  • Save the state of each page (this is a viewmodel) every time you navigate from it, so that it is saved if the application terminates and resumes during the tombstone process.
  • In the case of a deactivated application, view all pages in the navigation stack and save their state (their viewing mode), and then re-enter it in the event activated by the application.

What is the correct way to handle it?

thanks simone

+3
source share
4 answers

Unfortunately, the “best” time to save state will depend on: the application; the complexity of the models used by each page; the interaction supported by each page; and the complexity of the models shared between pages (at the application level).

As a rule, I try to use one model at the application level and save this when activating / deactivating. The page model is a link to a part of the application level model, and I save only specific information about page navigation on the page.

Examples of information about a particular page that I save are: entered but unsaved data; and scroll positions.

+2
source

I suppose it depends on your needs, but it is unlikely that you need to deviate from the documentation, which assumes a deactivated application event as a suitable place to save permanent and temporary data states, while closing should save only. Overview of the execution model (see the control block diagram in the Activation section)

This article also provides a worthy explanation with examples of application and tombstone life cycles, differentiating between retreat / close, decontamination, and tombstone.

You cannot expect the user to change the foreground application between page changes. However, you can expect what happens when you close or deactivate. Therefore, preserving the state of the page between views seems outsider.

+3
source

I can’t vote for the previous answer because I don’t have enough “reputation”, but yes, any information about the state of the transient should be stored in the Application.Deactivated event and then restored in the Application.Activated application to support the tomb.

If you need to store something between application sessions, you can use the Application.Closing event, but depending on what you need to store, you can just store it whenever it changes. Again, depending on what you need to save, you can either restore it in the Application.Launching event, or just read it when you need it.

+1
source

This is what I even thought about.

I have summarized my view on this.

Save as soon as possible.

What this means, besides any other imperatives that motivate you to postpone your salvation, make your salvation at the earliest opportunity. You can save directly to your main store, or you can save a transition state specifically for tombstone processing. You can save in the background while the page is open. You can save when the user requests a move between pages.

In situations where something unexpected can happen, for example, loss of power, an exception requiring the attention of users (in the absence of time for this, if it is deactivated), saving early offers is slightly more dependent on the user.

Imperatives that may prompt you to postpone conservation may include

  • Depending on your architecture, it may be inconvenient to implement page-level data storage.
  • Depending on the amount of data that needs to be stored and the architecture of the isolated storage model, this can lead to performance degradation, essentially for storage at the page level or at the level.
+1
source

Source: https://habr.com/ru/post/1384345/


All Articles