2

在我的应用程序中,我在表格视图上有一个过滤功能,可以在表格中提供过滤结果。我在共享首选项中设置了过滤选项(复选框),所以下次用户进入过滤器屏幕时,它会看到复选框被选中,因此它知道表格过滤了什么以及他上次为过滤检查了什么。

当应用程序启动时,我将它们全部设置为未选中(要求),但我不知道应用程序何时启动或恢复。当应用程序从内存中恢复时,它再次初始化了我所有的数据类型。我如何检查应用程序是否已恢复。如果我在活动 onResume 中设置东西 - 每次我只想知道应用程序何时恢复时都会调用它。

现在会发生什么我不知道应用程序何时从内存中恢复,我的过滤器的行为就像应用程序启动并将所有设置为未选中

4

4 回答 4

1

我所做的是,在我的第一个活动中创建了一个布尔值并将其设置为 false 并将其存储在共享首选项中,然后在开始过滤时将其设置为 true。所以它仍然是正确的,因为应用程序保留在内存中并且甚至可以恢复。当应用程序退出,并在启动时再次启动它再次变为假

于 2012-09-06T04:43:34.640 回答
0

没有“从记忆中恢复”状态。它要么被恢复,要么被创建(或重新启动)。所以你应该重写你的应用程序逻辑并初始化你的东西onCreate()而不是onResume()

于 2012-09-04T10:46:27.663 回答
0

You can restore your checkboxes on onRestart(), that means your activity was not killed and is resumed after it had been stopped(either manually or by android).

于 2012-09-04T10:56:25.893 回答
0

I am not able to understand you question properly, but as far as my understanding goes, you are filtering user options through shared preferences. If this is so, you need not unset/set each option programatically. Android remembers and and restores this for you. If you want to access these, just call context.getSharedPreferences() and from sharedPreferences object received call getBoolean (key,defValue).

于 2012-09-04T10:57:47.083 回答