Android的:是的onPause()保证完成后调用()? [英] Android: Is onPause() guaranteed to be called after finish()?
问题描述
找不到坚实的答案,这在任何地方。我有一个在这里完成()被调用的方法,并在onPause()被称为后
Couldn't find a solid answer to this anywhere. I have a method where finish() is being called, and onPause() is called afterward.
时保证通话后,被要求完成的onPause()()?
Is onPause() guaranteed to be called after a call to finish() ?
推荐答案
Android将一般称之为的onPause()
如果你调用完成()
在你Activity的生命周期中的某些点,除非你调用完成()
你的的onCreate()
Android will generally call onPause()
if you call finish()
at some point during your Activity's lifecycle unless you call finish()
in your onCreate()
.
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
finish();
}
@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause");
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy");
}
}
运行,并观察日志将只包含的onDestroy。呼叫完成()
几乎任何地方,你会看到所谓的onPause()。
Run, and observe that your log will only contain "onDestroy". Call finish()
almost anywhere else and you'll see onPause() called.
这篇关于Android的:是的onPause()保证完成后调用()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!