当前位置:网站首页>In an activity, view postdelay will cause memory leakage, but will not affect the life cycle execution of the activity.

In an activity, view postdelay will cause memory leakage, but will not affect the life cycle execution of the activity.

2022-06-11 07:55:00 tinyvampirepudge

Activity in ,View#postDelay Memory leaks can result , But it won't affect Activity Life cycle execution of .

The test code is as follows :

@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, " I am a delay message ");
        }
    }, 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 as follows :

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:  I am a delay message 
原网站

版权声明
本文为[tinyvampirepudge]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110747210916.html