在一个 Android 教程中,我看到了这个函数的用法。我认为他在那里使用它来恢复应用程序的前一个 session ,但问题是我无法在我的类中验证此功能,并且两个类(我的和他的)都从 ListActivity 扩展。
@Override
protected void onFreeze(Bundle outState) {
super.onFreeze(outState);
outState.putLong("feed_id", feed.feedId);
outState.putString("title", feed.title);
outState.putString("url", feed.url.toString());
}
此外,我在之前的一些函数调用中遇到了一些问题,比如他调用 list.next() 来操作 ArrayList,而我没有这样的函数,所以我使用了 list.MoveToNext()。 这可能是因为不同版本的 Android(我使用 1.6)以及使用什么来替代此功能?
最佳答案
我认为本教程非常非常古老。实际上,不再使用 onFreeze() 方法。来自 the (August 2008) Android 0.9 SDK Beta release notes :
onFreeze(Bundle) renamed to onSaveInstanceState(Bundle), to better reflect the fact that it does not represent an actual change in application lifecycle
关于android - 为什么要使用 onFreeze()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3279518/