我正在尝试从一个从服务器获取数据的活动启动意图服务,并尝试使用广播接收器在另一个活动中获取该数据但是广播接收器类没有被调用,我已经在清单中注册了我的服务类
这是我启动服务的代码
InviteReferrals
类MyWebRequestService
Intent intent = new Intent(LoginActivity.this, MyWebRequestService.class);
startService(intent);
我希望接收数据的活动
//inside on handle intent
new AsynchCall().execute();
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(MyWebRequestReceiver.PROCESS_RESPONSE);
broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
//here I am getting the data in my arraylist
broadcastIntent.putStringArrayListExtra("namelist", servicelist);
sendBroadcast(broadcastIntent);
在同一项活动中,我编写了广播接收器类
IntentFilter filter =IntentFilter(MyWebRequestReceiver.PROCESS_RESPONSE);
filter.addCategory(Intent.CATEGORY_DEFAULT);
receiver = new MyWebRequestReceiver();
registerReceiver(receiver, filter);
答案 0 :(得分:0)
确保接收器
registerReceiver(receiver, filter);
在发送广播之前调用
sendBroadcast(broadcastIntent);