我有一个活动多数民众赞成等待用户按图像。如果用户在3秒钟内不按任何东西,我想关闭活动(完成())。 这就是我的代码:如何在Android中唤醒一个线程睡眠
private final int delay = 3000;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.after_hangup);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
final ImageView pressToLaunchbrowser = (ImageView) findViewById(R.id.after_hang_up_image);
pressToLaunchbrowser.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); // if we want to open the device.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
Thread.interrupted();
}
});
new Thread() {
public void run() {
try {
Thread.sleep(delay);
finish();
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}}
我的问题是如何唤醒线程,如果新闻媒体是?我试过Thread.interrupted();
,但它不工作。该线程仍然等待3秒,如果我按或不。谢谢!
而不是仅仅倾销代码,你能解释一下吗?为后代提供一些细节,以便人们可以从中学习? – Gray 2012-08-01 13:26:00
重要的一切都在以下答案中进行解释 – 2012-08-01 13:27:37
您应该将该文本复制到此答案的顶部,然后才能接受此答案。 – Gray 2012-08-01 13:30:34