Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我的广播接收器类没有被调用_Android_Arraylist_Collections_Broadcastreceiver_Intentservice - Fatal编程技术网

Android 我的广播接收器类没有被调用

Android 我的广播接收器类没有被调用,android,arraylist,collections,broadcastreceiver,intentservice,Android,Arraylist,Collections,Broadcastreceiver,Intentservice,我正在尝试从一个活动启动一个意图服务,该活动从服务器获取数据,并尝试使用广播接收器在另一个活动中获取该数据,但广播接收器类没有被调用,我也在清单中注册了我的服务类 这是我启动服务的代码 Intent intent = new Intent(LoginActivity.this, MyWebRequestService.class); startService(intent); 类MyWebRequestService //inside on handle intent new Async

我正在尝试从一个活动启动一个意图服务,该活动从服务器获取数据,并尝试使用广播接收器在另一个活动中获取该数据,但广播接收器类没有被调用,我也在清单中注册了我的服务类

这是我启动服务的代码

 Intent intent = new Intent(LoginActivity.this, MyWebRequestService.class); 
 startService(intent);
类MyWebRequestService

//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);
在同一活动中,我编写了广播接收器课程

public class MyWebRequestReceiver extends BroadcastReceiver
{
  public static final String PROCESS_RESPONS = "com.rentpro.PROCESS_RESPONSE";

    @Override   
    public void onReceive(Context context, Intent intent) 
    {   
       listofnames = intent.getStringArrayListExtra("namelist");
    }
}

确保接收器

registerReceiver(receiver, filter);
在发送广播之前调用

sendBroadcast(broadcastIntent);

另外,最好在活动的
onPause()
方法中调用
unregisterReceiver()
,以确保应用程序不会泄漏接收器。是的,我已经在onPause中调用了它,但如何在发送广播(broadcastIntent)之前调用registerReceiver(接收器,过滤器);在我的情况下,我必须参考此链接