我有代码
public class intentService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
RequestQueue queue = MyVolley.getRequestQueue(this);
queue = MyVolley.getRequestQueue(this);
GsonRequest<Transport> gsonRequest = new GsonRequest<Transport>(
url_transports, Transport.class, null, createMyReqSuccessListenerTransport(),
createMyReqErrorListenerTransport());
Intent updateIntent = new Intent();
updateIntent.setAction(ACTION_UPDATE);
updateIntent.addCategory(Intent.CATEGORY_DEFAULT);
updateIntent.putExtra(EXTRA_KEY_UPDATE, 50);
this.sendBroadcast(updateIntent);
//工作
意图正在发送更新值
private Response.Listener<Transport> createMyReqSuccessListenerTransport() {
return new Response.Listener<Transport>() {
@Override
public void onResponse(Transport response) {
// send beetwean data
Intent updateIntent = new Intent();
updateIntent.setAction(ACTION_UPDATE);
updateIntent.addCategory(Intent.CATEGORY_DEFAULT);
updateIntent.putExtra(EXTRA_KEY_UPDATE, (i * 100) / size);
**sendBroadcast(updateIntent); // dosn`t work**
}
dosn`t work
答案 0 :(得分:0)
我自己决定了这个问题
我必须从句柄
调用intent handler.post(new Runnable() {
@Override
public void run() {
// send beetwean data
Intent updateIntent = new Intent();
updateIntent.setAction(ACTION_UPDATE);
updateIntent.addCategory(Intent.CATEGORY_DEFAULT);
updateIntent.putExtra(EXTRA_KEY_UPDATE, (finalI * 100) / size );
sendBroadcast(updateIntent);
}
});