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);
  }
1

There are 1 answers

0
Clocker On

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.