作者fake01 (code)
看板AndroidDev
标题Re: [问题] android Service ?
时间Sun Jun 2 23:11:03 2013
後来我发现是
Intent intent=new Intent();
intent.setClass(MainActivity.this,fileAdd.class);
Bundle bundle=new Bundle();
bundle.putString("str",saveStr);
intent.putExtras(bundle);
startActivity(intent);
这里造成我不能按menu,後来将另一个java档的class内容,移到同一个java下,
就解决问题了,不过我还是想问下次如果再遇到同样问题该如何解决,我有看到上一篇
有人回答用handler但是我本身这段程式码就是写在handler里面,我将程式码在列在下方
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE:
byte[] readBuf = (byte[]) msg.obj;
int [] dataBuf = new int [msg.arg1];
for(int i=0;i<msg.arg1;i++)
dataBuf[i] = readBuf[i] & 0xff;
int [] handleBuf = new int [5];
handleBuf[0]=dataBuf[1]*256+dataBuf[2];
handleBuf[1]=dataBuf[3]*256+dataBuf[4];
handleBuf[2]=dataBuf[5];
handleBuf[3]=dataBuf[6];
handleBuf[4]=dataBuf[7]*256+dataBuf[8];
String SaveStr="....";
tvOutPutOne.setText(Integer.toString(handleBuf[2]));
tvOutPutTwo.setText(Integer.toString(handleBuf[3]));
Intent intent=new Intent();
intent.setClass(MainActivity.this,fileAdd.class);
Bundle bundle=new Bundle();
bundle.putString("str",saveStr);
intent.putExtras(bundle);
startActivity(intent);
break;
};
这个handler 是由另一个java回传的讯息,我有想用再另一个handler来处理,
但我不知道该如何得到这个handler 内的变数(byte [] readBuf)?
问题
1. 原本就已经使用handler,但同样会造成menu无法点选,该如何解决?
2. 如何取的上述handler内的变数?
谢谢大家
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.241.209.170
1F:→ KeySabre:送message是谁? 何时送? menu不能按是否是因为ui thread 06/03 01:46
2F:→ KeySabre:被占用所以无法处理keyevent? 前文说会频繁使用,指的是 06/03 01:46
3F:→ KeySabre:这整段handle MESSAGE吗? 那就是频繁startActivity? 06/03 01:46
4F:→ Jyie:请问handler是ui thread的吗? 耗时的工作你还是让ui thread 06/03 09:04
5F:→ Jyie:去做,这样子你写handle有甚麽意义勒? 06/03 09:05
6F:→ KeySabre:他的handler可以做TextView setText,是在ui thread。 06/03 12:01
7F:→ Jyie:照他说卡住的地方应该是在它跳过去的Class下卡住的吧? 06/03 12:17
8F:→ fake01:K大 message 是另一个 handler 传回来的讯息 06/03 12:32
9F:→ fake01:mHandler.obtainMessage(Activity.MESSAGE,,); 06/03 12:33
10F:→ fake01:应该不是调整ui 的时候有问题 .setText();是不会卡住的 06/03 12:33
11F:→ fake01:当我注解 //startActivity(); 就不会有卡住的现象 06/03 12:34
12F:→ Jyie:你有没有考虑检查看看fileAdd.class的Code 06/03 12:49
13F:→ KeySabre:上一篇文说的一秒100笔是指一秒送一百次MESSAGE吗? 06/03 15:06
14F:→ KeySabre:fileAdd的onNewIntent有收到更新的值吗? 06/03 15:09