- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 Intent 打开位置设置菜单以在我的 Activity 中启用 gps。调用 Intent 后我使用服务来收听位置更新。我发送了两个 BroadcastReceivers
从 Service 到 Activity。在 Activity 的 onResume()
方法中,我想访问从 Service 传递的数据。但是当我单击后退按钮时,应用程序崩溃了。它说 BroadcastReceiver
尚未注册。但是我已经注册了两个 BroadcastReceivers
。
错误:
java.lang.RuntimeException: Unable to destroy activity {com.example.jobinsabu.ohxee/com.example.jobinsabu.ohxee.AddOffers.AddOffers}: java.lang.IllegalArgumentException: Receiver not registered: com.example.jobinsabu.ohxee.AddOffers.AddOffers$7@8cd71b4 at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4137) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4155) at android.app.ActivityThread.access$1500(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1484) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5910) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200) Caused by: java.lang.IllegalArgumentException: Receiver not registered: com.example.jobinsabu.ohxee.AddOffers.AddOffers$7@8cd71b4 at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:830) at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1850) at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:518) at com.example.jobinsabu.ohxee.AddOffers.AddOffers.onDestroy(AddOffers.java:448) at android.app.Activity.performDestroy(Activity.java:6418) at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1153) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4124) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4155) at android.app.ActivityThread.access$1500(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1484) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5910) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
代码:
StatsGpsService.java
public class StatsGpsService extends Service {
LocationListener locationListener;
LocationManager locationManager;
boolean flag1;
public StatsGpsService() {
super();
}
@Override
public void onCreate() {
super.onCreate();
Log.e("Service","Created");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
handleLocation(intent);
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
Log.e("Service","Destroyed");
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
public void handleLocation(Intent intent){
if(intent!= null) {
flag1 = intent.getBooleanExtra("offr_act_ind", false);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
if (flag1 == true) {
Intent intent = new Intent("loc_updts");
intent.putExtra("stat_lat", location.getLatitude());
intent.putExtra("stat_longt", location.getLongitude());
sendBroadcast(intent);
}
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
Log.e("Provider","Disabled");
Intent intent1=new Intent("offr_prvdr_disable");
intent1.putExtra("offr_provider_disable",true);
sendBroadcast(intent1);
}
};
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, locationListener);
}
}
}
AddOffers.java:
@Override
protected void onResume() {
super.onResume();
broadcastReceiver1 =new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent!=null){
if(intent.getBooleanExtra("offr_provider_disable",false)==true){
offer_gps=false;
Log.e("gps","disabled");
}
}
}
};
this.registerReceiver(broadcastReceiver1,new IntentFilter("offr_prvdr_disable"));
broadcastReceiver=new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent!=null){
lat=Double.toString(intent.getDoubleExtra("stat_lat",0.0));
longt=Double.toString(intent.getDoubleExtra("stat_longt",0.0));
offer_lat_txt.setText(lat);
offr_long_inpt.setText(longt);
}
}
};
this.registerReceiver(broadcastReceiver,new IntentFilter("loc_updts"));
}
@Override
protected void onStop() {
super.onStop();
if(static_gps_intent!=null){
stopService(static_gps_intent);
}
if(broadcastReceiver1!=null){
unregisterReceiver(broadcastReceiver1);
}
if(broadcastReceiver!=null){
unregisterReceiver(broadcastReceiver);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if(broadcastReceiver1!=null){
unregisterReceiver(broadcastReceiver1);
}
if(broadcastReceiver!=null){
unregisterReceiver(broadcastReceiver);
}
if(static_gps_intent!=null){
stopService(static_gps_intent);
}
}
最佳答案
那是因为 - 您正在注销 broadcastreceiver
both 方法中的 s onStop()
和 onDestroy()
.
您必须一次注销接收器。尝试从 onStop()
中删除注销代码方法。
关于Android广播接收器未注册报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42671318/
我正在努力学习本教程 https://github.com/cf-platform-eng/spring-boot-cities/tree/master/cities-service在 Cloud F
0){ echo "Username or email already exists."; }else{ $query = mysql_que
我想在Linux上编译ARToolKit源码,下载源码,按照ARToolKit文档,配置GLUT , OpenGL, libjpeg 等库。 转到 ARToolKit 目录并键入 ./Configer
你好,我在这个程序中遇到错误,wcout 不是 `std' 的成员。如您所见,我也使用了 iostream,但没有用。我有 Dev-C++ 4.9.9.2,我的操作系统是 XP SP3我需要你的帮助。
我尝试对一个网站进行多次投票,但我得到: panic: runtime error: invalid memory address or nil pointer dereference [signal
当我将“ using namespace std; int main(){ string s[30]; int n = 20; for(int i = 0; i using
我设置了 EMAIL_URL process.env.MAIL_URL="smtp://xx%40gmail.com:yyy@smtp.gmail.com:465" 这个工作找到了 Email.sen
我有如下文件夹结构 . ├── docker-compose.yml └── web-app ├── create_tomcat_admin.sh ├── Dockerfile
这是我在 php 中的查询代码: $query3 = mysql_query("SELECT * FROM area_of_work") or die('Invalid query:'. mysql_
我正在尝试将 therubyracer/therubyracer-heroku 安装到我的应用程序,因为它在 heroku 服务器中不起作用,因为我没有 javascript 运行时环境。 当我尝试安
我正在开发一个非常简单的 React 应用程序。它有一个组件,在这个组件中,我试图在单击链接时设置状态。但出于某种原因,setState 甚至没有得到认可。它带有下划线,表示未解析的函数或方法 set
我有三个来源:代码处理.h typedef enum {typeBool, typeVarDeclaration, typeFuncDeclaration } nodeEnum; typedef st
我正在尝试从我的 Android 手机向 raspi 发送连续的命令。我使用了此链接中的代码,但出现错误。 链接:https://stackoverflow.com/questions/2347143
我正在尝试从数据库中加载数据并将其放入不同的 View 中。 log cat 返回错误,它找不到“_id”列。 有人可以帮我解决这个问题吗? SqlHelper代码: public class Fib
我的alertview给出了这个问题..它与sqlite无关..它给出了一些信息.. 我该如何解决这个问题? UIAlertView *infoShow = [[UIAlertView alloc]
这个问题在这里已经有了答案: launch activities from different package (5 个答案) 关闭 10 年前。 最近我一直在开发一个新的应用程序,我正在尝试使用
这是我的代码: #include #include typedef struct test { int *a; char *s; }TEST; int main (void) {
所以我定义了一个函数,如果它是由它的 lonesome 实现的,那么它非常适合对线性数组进行合并排序,但是如果我把它放到一个类中,它就会出错。我认为这是一个很好的例子,说明我不太了解类(class)的
我是 IOS 新手。我有一个示例项目,并试图在此基础上学习 Obj-C。 现在我正处于学习如何使用 UIAlertController 的阶段。我有这样的代码: if (loanAmount == 0
当我尝试使用 wincachegrind 并获取 cachegrind 文件时,它返回 Cannot find call target. cachegrind.out line number:68 有
我是一名优秀的程序员,十分优秀!