简体   繁体   English

finish()和android活动生命周期

[英]finish() and android activity lifecycle

There are some things I don't know about android activity lifecycle, don't get me started on fragments!: 关于Android活动生命周期,有些事情我不了解,也不要让我开始了解片段!:

Once a method like resume() is called will it proceed to be executed to the very end if finish() or startActivity(new Intent(..)) is called. 一旦调用了诸如resume()之类的方法,如果调用了finish()或startActivity(new Intent(..)),它将继续执行到最后。

 public void onResume(){

      // do some stuff AAA
       ....

      startActivity(new Intent(..));

     // do some more stuff BBBB

      // Do I get this far?

      setResult(RESULT_CODE, intent);


     finish();


     // How about here? Do I get this far?  

    // how do I make sure that everything started in this app up to now is finished off as well? ie that activities started up by this activity are also finished?

}

Btw, this is a similar to top interview question. 顺便说一句,这与热门面试问题相似。 Will onPause() still get called after finish()? 在finish()之后仍然会调用onPause()吗? how about onStop()? onStop()怎么样?

Lastly, I would like to know how to finish() not just the MainActivity but all such activities that have started under the application, ie started by MainActivivity, thus going back to the application that originally called my application. 最后,我想知道如何不仅完成MainActivity的finish(),还知道如何在应用程序下启动的所有此类活动,即由MainActivivity启动的活动,从而回到最初调用我的应用程序的应用程序。

Yes the code after the call to finish() will be called. 是的,将调用对finish()调用之后的代码。

when you call finish() the next function that will be executed is onPause() . 当您调用finish() ,将要执行的下一个函数是onPause()

If you want to close all activities on the back stack do this: 如果要关闭后台堆栈上的所有活动,请执行以下操作:

setResult(RESULT_CLOSE_ALL);
finish();

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

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