public OnPause() 中的字符串数组

public string array in OnPause()

谁能给我解释一件事? 我正在尝试将 OnPause() 用于我的应用程序。当用户选择其他应用程序并且我的应用程序不再可见时,我的应用程序的 OnPause() 完美启动。例如,我试图在 OnPause() 中使用一些方法来保存一些数据。我注意到在 OnPause() 中,我可以使用我的应用程序的一些 public 变量进行操作(分配数据、检索数据等),但是我的 public 字符串数组填写有问题在 OnCreate 中。
例如,如果我尝试执行:在 OnPause() 中执行 String temp_str = my_array[1],我的应用程序会崩溃并显示 "Source code does not match the bytecode" 之类的解释。任何人都可以提示为什么会发生这种情况:public 变量在 OnPause() 中使用得很好,但是对于 public 数组我有问题吗?

来自Android Developing Guide, in the onPause() lifecycle section found here

onPause() execution is very brief, and does not necessarily afford enough time to perform save operations. For this reason, you should not use onPause() to save application or user data, make network calls, or execute database transactions; such work may not complete before the method completes. Instead, you should perform heavy-load shutdown operations during onStop()

因此,最好的解决方案是将您的方法调用移至 onStop() 应用程序状态。 onStop()onPause() 之后,当应用程序不再可见或您即将完全关闭应用程序时被调用。