简体   繁体   English

更改捆绑包saveInstanceState

[英]Altering Bundle savedInstanceState

I want to create an app that acts as frontend to launch an emulator with preloaded game. 我想创建一个充当前端的应用程序,以启动带有预装游戏的模拟器。

I have the emu source code, but I can't edit it. 我有emu源代码,但无法编辑。 In the onCreate(Bundle savedInstanceState) method of the emulator's main activity there is this line: 在模拟器的主要活动的onCreate(Bundle savedInstanceState)方法中,存在以下行:

if (savedInstanceState != null)
    currentGame = savedInstanceState.getString("currentGame");

Which seems the line that makes the emulator run the latest game if one is found when the activity is (re)created. 如果在创建(重新)活动时发现模拟器,那么似乎这条线使模拟器运行最新的游戏。

Is there a way to edit the savedInstanceState so that it contains the currentGame string? 有没有一种方法可以编辑savedInstanceState,使其包含currentGame字符串?

when the activity is first created the savedInstanceState is null, and in subsequent calls it's not. 首次创建活动时, savedInstanceState为null,而在随后的调用中则不是。 To make sure that the savedInstanceState is not null, there is a method called onRestoreInstanceState() that you should override, and for sure it has the string you're looking for. 为确保savedInstanceState不为null,您应该重写一个名为onRestoreInstanceState()的方法,并确保它具有您要查找的字符串。

but i think that what you realy want is to send an intent to that activity with a Bundle already filled with that string. 但是我认为您真正想要的是使用已经填充了该字符串的Bundle向该活动发送意图。 if it's not what you want please explain a little more what is your problem. 如果不是您想要的,请多解释一些问题。

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

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