简体   繁体   English

Android销毁后正在使用相同的实例活动

[英]Android is using the same instance activity after destroyed

  • I'm using a LoginActivity to Log in with Smart Lock . 我正在使用LoginActivity使用Smart Lock登录。
  • I start the LoginActivity as startActivityForResult . 我以startActivityForResultLoginActivity启动LoginActivity I'm interested in if Smart Lock has a credential, and return RESULT_OK if everything is ok. 我对Smart Lock是否具有凭据感兴趣,如果一切正常,则返回RESULT_OK Then I call finish() : 然后我调用finish()

     loginActivityViewPresenter.setResult(RESULT_OK) loginActivityViewPresenter.finish() 

After this, onDestroy() is called. 此后,将调用onDestroy() Let's imagine this is the instance @7161 . 假设这是@7161实例。

Then I log out, and I want to log in again, and the same instance is on the top @7161 . 然后我注销,然后再次登录,同一实例位于顶部@7161

Functions like isDestroyed() or isFinishing() are always true. 诸如isDestroyed()isFinishing()类的函数始终为true。

Why? 为什么?

It looks like the AsyncTasks you are using or some other object are keeping are a reference to your activity and the android framework is using that existing activity when you start it again. 看来您正在使用的AsyncTasks或保留的其他一些对象是对您的活动的引用,并且当您再次启动它时android框架正在使用该现有活动。

You can determine this by doing a heap dump after finishing the activity and looking at the references to this activity. 您可以通过在完成活动并查看对该活动的引用之后进行堆转储来确定此情况。

You could also use a tool called Leak Canary. 您也可以使用一个名为Leak Canary的工具。

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

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