如何受益于“温暖的开始”从保存的实例状态束传递到ongreate()或onrestoreInstanceState()

发布于 2025-02-01 20:54:11 字数 1333 浏览 3 评论 0 原文

阅读了这些Android文档后,我们对如何从“温暖起始问题”中受益的状态捆绑包中的“温暖起始问题”感到困惑,该状态束传递到otCreate()或onrestoreInstancestate((())。 在保存状态的文档中,它说“保存的实例状态”仅保存用于原始类型和简单的小对象,例如字符串。这显然无法节省大量的开始时间。以及“活动 - 差异文档”中的示例代码,它节省了游戏的预级级别和得分,并建议这可以缩短开始时间。但是如何?他是否暗示我们只能使用水平和得分来减少对象的必要加载?但是,我们真的可以从保存的实例状态中受益吗?

我们找不到实际的示例代码来显然减少这些文档的温暖开始时间。有些人真的从保存的实例中受益吗?

https://developer..android.com/topic/topic/topic/performance/performance/vitals/vitals/启动时间#温暖

该系统从内存中驱逐您的应用程序,然后将用户重新发布。过程和 活动需要重新启动,但是该任务可以从保存的实例状态中受益 束传递到onCreate()。

(保存的实例状态)仅适用于原始类型和简单的小对象,例如字符串

​em>此Doucment具有示例代码,可以恢复一些级别和分数的信息。

  public void onRestoreInstanceState(Bundle savedInstanceState) {
    // Always call the superclass so it can restore the view hierarchy
    super.onRestoreInstanceState(savedInstanceState);
    // Restore state members from saved instance
    currentScore = savedInstanceState.getInt(STATE_SCORE);
    currentLevel = savedInstanceState.getInt(STATE_LEVEL);
  }

After reading these Android documents, we feel confused about how to benefit on "warm start issue" from the saved instance state bundle passed into onCreate() or onRestoreInstanceState(().
In the document of saving-states, it says the "Saved instance state" saves only for primitive types and simple, small objects such as String. This obviously can't save significant start time. And the sample code in the activity-lifecycle document, it saves the pre-played level and score of a game and suggests this can shorten start time. But how? Does he imply we can use only the level and score to reduce necessary loading of objects? But can we really benefit from the saved instance state to do that?

We cannot find actual sample code to obviously reduce warm start time from these documents. Do some guys really benefit from the saved instance?

https://developer.android.com/topic/performance/vitals/launch-time#warm

The system evicts your app from memory, and then the user re-launches it. The process and the
activity need to be restarted, but the task can benefit somewhat from the saved instance state
bundle passed into onCreate().

https://developer.android.com/topic/libraries/architecture/saving-states

(Saved instance state)only for primitive types and simple, small objects such as String

https://developer.android.com/guide/components/activities/activity-lifecycle#asem

This doucment has sample code to restore some information of level and score like a game.

  public void onRestoreInstanceState(Bundle savedInstanceState) {
    // Always call the superclass so it can restore the view hierarchy
    super.onRestoreInstanceState(savedInstanceState);
    // Restore state members from saved instance
    currentScore = savedInstanceState.getInt(STATE_SCORE);
    currentLevel = savedInstanceState.getInt(STATE_LEVEL);
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素年丶 2025-02-08 20:54:11

在温暖状态的情况下, onsaveinstancestate 是,即使在过程死亡中也持续存在。如果您检查文档,但它指出该捆绑包已序列化/应序列化为磁盘。如果数据是复杂的,而与示例中的原始性相似,则此过程可能会很慢。

无论哪种方式,活动#ongreate都将与保存(或不保存)的捆绑包一起调用。使用或不取决于您的数据。

In the case of WARM state the bundle from onSaveInstanceState will be persisted even across process death. If you check the docs though it states that the bundle is serialized/deserialized to disk. This process can be slow if the data is complex vs a primitive like in the example.

Either way Activity#onCreate will be called with the bundle that was saved (or not). Use it or don't depends on your data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文