这个问题已经讨论了很多次,但是我想澄清我的具体情况。
public class LoggerActivity extends Activity
{
...
private Thread mInnerThread = new Thread()
{
public void run()
{
...
try
{
...
String line = "";
while ((line = bufferedReader.readLine()) != null && !isInterrupted())
{
mUIHandler.sendMessage(mUIHandler.obtainMessage(0, line))
}
...
}
catch (InterruptedException ex)
{
}
}
mUIHandler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
mLoggerView.append((String)msg.obj + "\n");
}
};
...
@Override
protected void onDestroy()
{
mInnerThread.interrupt();
super.onDestroy();
}
}
只有InnerThread可以将消息发送到mUIHandler
,但是我在onDestroy
中将其中断。我认为可以等到InnerThread的所有消息都将被处理后再进行GCing mUIHandler
....
那么,您可以确认此代码是清晰的,我可以放心地忽略警告吗?