0
在我的android應用程序中,我使用一個線程來下載一些數據。在Android中強制關閉線程
這是目前工作代碼的原型:當下載數據形成的服務器是非常緩慢的發生
void startThread()
{
thread = new Thread(this);
thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
}
@Override
public void run()
{
while(application_running)
{
//download my data... (on slow server response, execution gets stuck here)
}
}
問題。雖然我關閉了應用程序:數據下載線程仍然活着。但是我需要這個線程在應用程序關閉後立即關閉。
有什麼辦法強制關閉它嗎?或者其他任何標準的方式來下載數據?
你可以在'onPause()'方法中調用'thread.interrupt()'方法來停止線程,併爲你的問題在慢速連接後發佈logcat錯誤 – 2014-09-21 06:58:41