Skip to content

Commit

Permalink
update HandlerThread
Browse files Browse the repository at this point in the history
  • Loading branch information
milovetingting committed Apr 3, 2019
1 parent f4646d2 commit 00e1984
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -30,6 +31,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe

private Handler mThreadHandler;

private Looper mThreadLooper;

private HandlerThread mHandlerThread;

@Override
Expand All @@ -45,7 +48,9 @@ protected void onCreate(Bundle savedInstanceState) {
mHandlerThread = new HandlerThread(THREAD_NAME);
mHandlerThread.start();

mThreadHandler = new Handler(mHandlerThread.getLooper(), new Handler.Callback() {
mThreadLooper = mHandlerThread.getLooper();

mThreadHandler = new Handler(mThreadLooper, new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
Expand All @@ -69,6 +74,7 @@ public boolean handleMessage(Message msg) {
protected void onDestroy() {
super.onDestroy();
mMainHandler.removeCallbacksAndMessages(null);
mThreadLooper.quit();
}

@Override
Expand Down

0 comments on commit 00e1984

Please sign in to comment.