在我的应用中,我有一个主题,我在startTimerThread()
onCreate
Thread th = new Thread(new Runnable()
{
public void run()
{
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "What the hell is this for?");
wl.acquire();
while (true)
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
try
{
//I do my stuff here
}
catch (Exception e) {}
}
});
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
});
private void startTimerThread()
{
th.start();
}
即使我按下" Back-Button"线程也会完美开启。在我的Android设备上,然后按下电源按钮
但是,如果我在应用程序运行时按下Powerbutton WHILE(因此没有按下" Back-Button"之前)线程被杀死。
我不知道为什么会发生这种情况......有没有人知道这个问题的解决方案?