Skip to content

Commit 243d725

Browse files
committed
add try catch for unregister receivers
c19354837#124
1 parent 6931259 commit 243d725

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

android/src/main/java/com/ninty/system/setting/SystemSetting.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ private void registerVolumeReceiver() {
7474

7575
private void unregisterVolumeReceiver() {
7676
if (volumeBR.isRegistered()) {
77-
mContext.unregisterReceiver(volumeBR);
77+
try {
78+
mContext.unregisterReceiver(volumeBR);
79+
} catch (RuntimeException e) {}
7880
volumeBR.setRegistered(false);
7981
}
8082
}
@@ -549,23 +551,33 @@ public void onHostPause() {
549551
@Override
550552
public void onHostDestroy() {
551553
if (wifiBR != null) {
552-
mContext.unregisterReceiver(wifiBR);
554+
try {
555+
mContext.unregisterReceiver(wifiBR);
556+
} catch (RuntimeException e) {}
553557
wifiBR = null;
554558
}
555559
if (bluetoothBR != null) {
556-
mContext.unregisterReceiver(bluetoothBR);
560+
try {
561+
mContext.unregisterReceiver(bluetoothBR);
562+
} catch (RuntimeException e) {}
557563
bluetoothBR = null;
558564
}
559565
if (locationBR != null) {
560-
mContext.unregisterReceiver(locationBR);
566+
try {
567+
mContext.unregisterReceiver(locationBR);
568+
} catch (RuntimeException e) {}
561569
locationBR = null;
562570
}
563571
if (locationModeBR != null) {
564-
mContext.unregisterReceiver(locationModeBR);
565-
locationBR = null;
572+
try {
573+
mContext.unregisterReceiver(locationModeBR);
574+
} catch (RuntimeException e) {}
575+
locationModeBR = null;
566576
}
567577
if (airplaneBR != null) {
568-
mContext.unregisterReceiver(airplaneBR);
578+
try {
579+
mContext.unregisterReceiver(airplaneBR);
580+
} catch (RuntimeException e) {}
569581
airplaneBR = null;
570582
}
571583
}

examples/SystemSettingExample/android/.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@
1414
<natures>
1515
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
1616
</natures>
17+
<filteredResources>
18+
<filter>
19+
<id>1661256726794</id>
20+
<name></name>
21+
<type>30</type>
22+
<matcher>
23+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
24+
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25+
</matcher>
26+
</filter>
27+
</filteredResources>
1728
</projectDescription>

0 commit comments

Comments
 (0)