当android中的方向发生变化时,将再次调用Random array

当android中的方向发生变化时,将再次调用Random array,android,random,orientation,Android,Random,Orientation,我想在我的应用程序中显示一些随机句子。因为这段代码在onCreate方法中,所以每次应用程序的方向改变时都会调用它 Here is my code for generating random list of array inside Oncreate method int listlen = list.size(); // get the size and gen the random index System.out.println("len" + listlen);

我想在我的应用程序中显示一些随机句子。因为这段代码在onCreate方法中,所以每次应用程序的方向改变时都会调用它

Here is my code for generating random list of array inside Oncreate method

      int listlen = list.size(); // get the size and gen the random index
     System.out.println("len" + listlen);
     Random indexval = new Random();
    int n = indexval.nextInt(listlen); // get random val
    System.out.println("random num " + n);
我无法在我的应用程序中添加这行代码

    android:configChanges="orientation|screenSize|keyboardHidden"

因为我是在方向改变时手动计算屏幕大小的,而且由于其他一些问题,我删除了上面的代码行。那么,是否有可能在应用程序打开时生成随机列表?因为当方向改变时,我会得到不同的随机单词。任何帮助都会很好!!感谢您,您可以在应用程序类内部,在onCreate中执行此操作。当您旋转时,除非configChanges行在清单中,否则整个活动将被终止并从onCreate重新启动。如果要确保使用相同的三个单词,请将它们保存在onSaveInstanceState中,并保存在onCreate或onRestoreInstanceState中。从捆绑包中获取它们。

您需要将n的值保存在onSaveInstanceState中,并在方向更改后还原。您能给我一个如何使用onSaveInstanceState的示例吗@盖布·塞尚