Let's clarify your question.
But before we do this, it's a fact about onSaveInstanceState - its call is called for various reasons, such as:
- orientation change
- transition from foreground to background (by pressing the home button or launching another action or click)
- the system is in low memory
Now, if your question is, “How can I simulate an onSaveInstance call just for testing purposes,” then Theo and Ted are the correct answer. Both changing the parameters of the developer’s parameters and clicking on the house will result in a call to onSaveInstance.
But it will just be a change of orientation (as you noted in your question), which makes me think that you can ask: "How can I simulate a call to the onSaveInstance method when the system is under low memory pressure"
The short answer to this question is the lack of an automated way to simulate a low memory state. The above methods only mimic the onSaveInstanceState method call, not the low memory condition as such
A few caveats here.
The first caveat to this is that under extreme conditions, the kernel "uncleanly" kills your process to require memory, which means that onSaveInstanceState will never be called. In these situations, testing onSaveInstanceState is controversial. There is not much you can do with this scenario, but the good news is that its a very rare esp event. for foreground operations.
The second caveat is that the ActivityManager can return your activity resource by "killing it cleanly", i.e. your onSaveInstance will be called. This happens with actions that are not in the foreground (i.e. not visible to the user, so that they are already in a stopped state), and the system is under pressure from the memory.
In this second caution, you cannot automatically simulate this condition. This can be done if you start working with heavy loads manually and hope that the ActivityManager will be forced to process one of your actions.
The more it is worth remembering, the more there is no need to simulate a low memory state. While you simulate how onSaveInstanceState is called, you automatically check the condition under which it can be called for low memory situations. And the easiest way to call this method is to change the orientation on the emulator (ctrl-f11). And if you use the actual device to temporarily change the developer settings ("Do not perform actions")
numan salati Feb 24 '13 at 2:39 2013-02-24 02:39
source share