Activity中,View#postDelay会导致内存泄漏,但是不会影响Activity的生命周期执行。
测试代码如下:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.e(TAG, "onCreate"); iv = findViewById(R.id.iv); iv.postDelayed(new Runnable() { @Override public void run() { Log.e(TAG, "我是延时消息"); } }, 10000); } @Override protected void onPause() { super.onPause(); Log.e(TAG, "onPause"); } @Override protected void onStop() { super.onStop(); Log.e(TAG, "onStop"); } @Override protected void onDestroy() { super.onDestroy(); Log.e(TAG, "onDestroy"); }
log如下:
2021-05-07 20:37:06.234 14974-14974/com.tinytongtong.androidstudy E/GlideV4Activity: onCreate 2021-05-07 20:37:07.844 14974-14974/com.tinytongtong.androidstudy E/GlideV4Activity: onPause 2021-05-07 20:37:08.245 14974-14974/com.tinytongtong.androidstudy E/GlideV4Activity: onStop 2021-05-07 20:37:08.249 14974-14974/com.tinytongtong.androidstudy E/GlideV4Activity: onDestroy 2021-05-07 20:37:16.304 14974-14974/com.tinytongtong.androidstudy E/GlideV4Activity: 我是延时消息