目前我的应用程序从对话框和线程中的服务器获取数据。 来电时应该做些什么。 现在我正在这样做。我想知道这种方法是对的还是别的什么都要做。来电处理线程
@Override
protected void onPause() {
// TODO Auto-generated method stub
Utility.debugger("PAUSE 1");
if (ScreenReceiver.wasScreenOn) {
// this is the case when onPause() is called by the system due to a screen state change
Utility.killDialog();
System.out.println("SCREEN TURNED OFF");
} else {
Utility.debugger("PAUSE 2");
// this is when onPause() is called when the screen state has not changed
}
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
Utility.debugger("PAUSE 3");
if (!ScreenReceiver.wasScreenOn) {
// this is when onResume() is called due to a screen state change
System.out.println("SCREEN TURNED ON");
Utility.debugger("PAUSE 4");
Utility.resumeDialog();
} else {
// this is when onResume() is called when the screen state has not changed
}
super.onResume();
}
public static void killDialog()
{
if(dialog != null || dialog.isShowing())
{dialog.dismiss();
t.interrupt();
try {
t.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void resumeDialog()
{
if(dialog != null )
{
dialog.setIndeterminate(true);
dialog.show();
t.run();
}
}
其中t是线程和对话框正在progressDialog。 我也喜欢暂停和恢复是设备进入睡眠状态。
谢谢!
我想在传入呼叫来临时停止对话框和正在运行的线程并在呼叫结束时重新启动,因为它会返回应用程序。 – voidRy
@ user983364线程无法暂停。打断他们通常是一个坏主意。但是,通常使用标志来模拟这种行为。例如'if(isPaused)Thread.sleep(100)' – spatulamania
thakx for information :)。 – voidRy