每当有新电子邮件到达收件箱时,我都会尝试收到通知,代码如下。我的应用程序在短时间内变得没有响应,虽然在 logCat 应用程序仍在与 imap 服务器通信....但 android 系统要求我等待或关闭此应用程序。这是因为“thread.sleep()”吗?我该如何解决?
任何人都可以指导我吗?:/
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
Log.d(TAG, "onStart");
//player.start();
//add listenser and keep listening
try{
folder.addMessageCountListener(new MessageCountAdapter() {//start
public void messagesAdded(MessageCountEvent ev) {
Message[] msgs = ev.getMessages();
// msgs.length
Log.d(TAG, "It is inside LISTENER");
}
});//end
for (; ;) {
Thread.sleep(20000); // sleep for freq milliseconds
// This is to force the IMAP server to send us
// EXISTS notifications.
Log.d(TAG, "AFTER SLEEP");
folder.getMessageCount();
}
}
catch(Exception e){
}
}