简体   繁体   English

Android不会调用onResume()

[英]Android won't call onResume()

I have the following problem: 我有以下问题:

  • I have Activity1 and Activity2 . 我有Activity1Activity2
  • I start Activity2 from Activity1 . 我开始Activity2 ,从Activity1
  • Activity1.onPause() is called. Activity1.onPause()被调用。
  • Activity2 finishes and closes and Activity1 restarts. Activity2完成并关闭, Activity1重新启动。 When this happens, nothing is called for Activity1 - neither onResume() , nor onCreate() , nor onStart() . 发生这种情况时, Activity1不会被调用onResume()onCreate()onStart()不会。

What should I do? 我该怎么办? I really need onResume() . 我真的需要onResume()

First of all: You tried to work with onCreate() on restart - this won't work. 首先:您尝试在重新启动时使用onCreate() -这行不通。 See important details on the Activity lifecycle to get used to its functions. 请参阅“ 活动”生命周期的重要细节以适应其功能。

Next, since onResume() and onStart() should work fine according to the Activity lifecycle, make sure your code is valid and contains no bugs. 接下来,由于onResume()onStart()在Activity的生命周期内应该可以正常工作,因此请确保您的代码有效并且没有错误。


However, you could try to call onRestart() , too. 但是,您也可以尝试调用onRestart() This is the best place to insert code which should only be executed if the Activity restarts. 这是插入代码的最佳位置,该代码仅在Activity重新启动时才应执行。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM