连续读取缓冲区停止App
我的应用程序从蓝牙设备接收源源不断的数据流。 我正在 while(true) 循环中读取此流,并且可以在日志中看到读取的数据。 问题是,我的设备不再响应。有没有一种(希望)简单的方法让应用程序在后台读取流?
谢谢! 基督教。
@博尔德: 抱歉,我不太明白 AsynkTask 类。 :( 你能帮我把这段代码放在后台吗? 非常感谢!
try {
while (true)
{
read = isBT.read(msgBuffer);
connected = true;
StringBuilder strBuffer = new StringBuilder();
for (int i = 0; i<read; i++)
{
int b = msgBuffer[i];
strBuffer.append(b);
}
Log.d(TAG,"++++++ Read "+ read + " Bytes: " + strBuffer.toString());
}
}
catch (IOException e) {
Log.d(TAG," +++ IOException ++++", e);
}
My App recieves a neverending datastream from a bluetooth device.
I am reading this stream in a while(true) loop and can see the read data in my log.
The problem is, that my device is not responding anymore. Is there a (hopefully) simple way to let the application read the stream in the background?
Thanks!
Christian.
@boulder:
Sorry, I don't really understand that AsynkTask class. :(
Can you please help me with this code putting it in the background?
Thank you very much!
try {
while (true)
{
read = isBT.read(msgBuffer);
connected = true;
StringBuilder strBuffer = new StringBuilder();
for (int i = 0; i<read; i++)
{
int b = msgBuffer[i];
strBuffer.append(b);
}
Log.d(TAG,"++++++ Read "+ read + " Bytes: " + strBuffer.toString());
}
}
catch (IOException e) {
Log.d(TAG," +++ IOException ++++", e);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能这会有所帮助 http://android-developers.blogspot.com /2009/05/painless-threading.html
处理程序示例:
May be this will be helpful http://android-developers.blogspot.com/2009/05/painless-threading.html
Handler example: