Skip to content

Commit 0ef71ce

Browse files
committed
Activity退出,view自动销毁。不用重写onestroy了
1 parent afe4e8f commit 0ef71ce

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

app/src/main/java/com/example/liangmutian/randomtextview/MainActivity.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,5 @@ public void start4(View v) {
6262

6363
}
6464

65-
@Override
66-
protected void onDestroy() {
67-
super.onDestroy();
68-
mRandomTextView.destroy();
69-
}
65+
7066
}

randomtextviewlibrary/src/main/java/com/example/liangmutian/randomtextviewlibrary/RandomTextView.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ public void run() {
272272
};
273273

274274

275+
@Override
276+
protected void onDetachedFromWindow() {
277+
super.onDetachedFromWindow();
278+
destroy();
279+
}
280+
275281
private void drawText(Canvas mCanvas, String text, float x, float y, Paint p) {
276282

277283
if (y >= -measuredHeight && y <= 2 * measuredHeight)

0 commit comments

Comments
 (0)