简体   繁体   English

在GWT中保存活动状态

[英]Saving activity state in GWT

I'm having hard times trying to figure out how the state of an activity can be saved in GWT, like in Android. 我很难弄清楚如何在GWT中保存活动状态,就像在Android中一样。

I mean, when an activity is going to be discarded how can we serialize its state somewhere and retrieve it when the activity is shown again ? 我的意思是,当一个活动要被丢弃时,我们如何在某个地方序列化它的状态并在再次显示该活动时检索它呢?

I've read the put into practice the following official guide 我已阅读以下官方指南,将其付诸实践
http://www.gwtproject.org/doc/latest/DevGuideMvpActivitiesAndPlaces.html http://www.gwtproject.org/doc/latest/DevGuideMvpActivitiesAndPlaces.html
but it doesn't say anything about my problem. 但这并没有说明我的问题。

Can you help ? 你能帮我吗 ?

EDIT: 编辑:

Now I'm wondering what's the use of Tokenizet getToken method is... 现在我想知道Tokenizet getToken方法的用途是什么...

public static class Tokenizer implements PlaceTokenizer<HelloPlace> {
        @Override
        public String getToken(HelloPlace place) {

            return place.getHelloName();
        }

        @Override
        public HelloPlace getPlace(String token) {

            return new HelloPlace(token);
        }
    }

Activity should not have a state. 活动不应具有状态。 A view has a state, and a view is not discarded when a user moves from place to place within an app. 视图具有状态,并且当用户在应用程序中到处移动时,视图不会被丢弃。

For example, an activity can load the data and populate the corresponding view. 例如,活动可以加载数据并填充相应的视图。 It can also set a flag in a view, eg populated = true . 它还可以在视图中设置标志,例如populated = true Next time an activity starts it can check if the view is populated and act accordingly. 下次活动启动时,它可以检查是否填充了视图并采取相应的措施。

The need for such flags is dictated by your requirements. 是否需要此类标志由您的要求决定。 Sometimes users expect to see a refreshed data every time they visit a place. 有时,用户希望每次访问某个地方时都会看到刷新的数据。 In other cases, it may not be necessary or practical. 在其他情况下,可能没有必要或不实用。

EDIT: 编辑:

Token is used to provide additional information to an activity about what a user expects to see in a view. 令牌用于向活动提供有关用户期望在视图中看到的内容的附加信息。 For example, a view can display information about a blogger. 例如,一个视图可以显示有关博客的信息。 Then a token may provide an id of a blogger that a user expects to see: 然后,令牌可以提供用户期望看到的博客作者的ID:

/#BloggerBio:12345

When BloggerBioActivity parses this token ("12345"), it knows to load the bio of a blogger with id=12345 and show it in the BloggerBioView. 当BloggerBioActivity解析此令牌(“ 12345”)时,它知道加载id = 12345的博客的简历,并将其显示在BloggerBioView中。

When a user visits this view again, it is up to you what happens. 当用户再次访问该视图时,由您自己决定将发生什么情况。 You may refresh the view even if the token is the same, or you can compare the token to the id of a blogger shown in a view, and if it is the same, do nothing. 即使令牌相同,您也可以刷新视图,或者可以将令牌与视图中显示的博客作者的ID进行比较,如果令牌相同,则什么也不做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM