Sheehan,关于onRetainNonConfigurationInstance(),下面是我目前为我的应用程序正在进行的工作。我觉得我虽然过于复杂,但我认为有一种更简单的方法;然而,这工作得很好,我现在:
所以在我的活动类 “RotationMenu.java”:
private Object catcher;
//lots of non-related code here
//directoryList is a returned list of selected directories, that I wish to
//retain in the event of an orientation state change.
String[] directoryList = new String[arrayList.size()];
arrayList.toArray(directoryList);
//here, I set the class Object catcher to the directoryList
catcher = directoryList;
//rest of non-related code
//this method is called when the orientation changes (for me,
//when I open my Droid's hardware keyboard)
public Object onRetainNonConfigurationInstance()
{
//If I've entered anything into my catcher Object, it will be kept
//across orientation changes.
final Object data = catcher;
return data;
}
现在,在我的onCreate(捆绑savedInstanceState)方法:
//We retrieve the stored Object and cast it to a String array
final Object recipient = (String[]) getLastNonConfigurationInstance();
//in case the state changes again before the code that sets the directories is run
catcher = recipient;
//if there was any stored data, we can now reinstate the list adapter where the
//directoryList was originally being used.
if(recipient != null)
{
returnedDirectories.setAdapter(new ArrayAdapter<String>(
this.getBaseContext(),
R.layout.simple_list_item_small,
(String[])recipient));
}
再次,这就是我目前的做法。如果有人知道一个更有效的方法,无论如何评论。 :)
我会尝试并将其实现到我自己的代码中!你知道我可以从我的/layout-land/main.xml中拉出chartImageViewLandscape吗?似乎它总是空! – 2010-09-03 22:07:56
根据我的理解,您不希望实际存储View对象,这会导致内存泄漏。取而代之的是,存储ImageView包含的位图或drawable,然后将其设置回onCreate()方法中的chartImageViewLandscape视图。 – kcoppock 2010-09-03 22:10:02
但我甚至无法设置chartImageViewLandScape,因为我需要能够通过findViewById将其挂接到布局 – 2010-09-03 22:11:57