简体   繁体   English

Android从onRestart访问onRestoreInstanceState

[英]Android access onRestoreInstanceState from onRestart

I am creating an android app with a timer. 我正在创建一个带有计时器的android应用。

When I change orientation, onSavedInstanceState and onRestoreInstanceState are called, which is great. 当我更改方向时,将调用onSavedInstanceStateonRestoreInstanceState ,这很棒。 However when I press the home button only onSavedInstanceState is called, but onRestoreInstanceState is not called. 但是,当我按下主页按钮时,仅onSavedInstanceState ,而没有调用onRestoreInstanceState

Can I access the saved variables from onRestart or perhaps call onRestoreInstanceState manually, but I don't know how? 我可以从onRestart访问保存的变量,还是可以手动调用onRestoreInstanceState ,但是我不知道怎么办?

You do not see onRestoreInstanceState() called because Android is not restoring you at that moment. 您不会看到onRestoreInstanceState()被调用,因为此时Android尚未还原您。 You pressed home, so launcher app should be brought to front 您按下了主页,因此启动器应用程序应该放在最前面

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

相关问题 澄清Android活动onPause和onRestart - Clarification Android Activity onPause and onRestart android在片段中使用什么代替onRestart() - android what to use instead of onRestart() in a fragment 如何从onRestart方法刷新TabbedActivity的视图 如何从其他类访问片段的view元素 - How to refresh TabbedActivity's View from onRestart method | How to access fragment's view element from other class 在android中实现Parcelable时,不会调用onRestoreInstanceState - implementing Parcelable in android, onRestoreInstanceState is not getting called Android-只能在onRestoreInstanceState()中还原saveInstanceState,而不能在onCreate()中还原 - Android - savedInstanceState can be restored only in onRestoreInstanceState() not in onCreate() Android onRestoreInstanceState在方向更改时未完全更新 - Android onRestoreInstanceState not updating fully on orientation change 如何使用onRestart()取消暂停/重新启动Android Activity中的线程? - How can I use onRestart() to unpause/restart a thread in an Android Activity? 如何序列化自定义对象列表并在Android中的RestoreInstanceState中恢复它? - How to serialize a List of custom objects and recover it onRestoreInstanceState in Android? onStart,onRestart和onStop - onStart, onRestart and onStop onSaveInstanceState和onRestoreInstanceState似乎不起作用 - onSaveInstanceState and onRestoreInstanceState seems not to work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM