Skip to content

Commit ad9b3d9

Browse files
committed
chore: pr comments
1 parent f3a1a81 commit ad9b3d9

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

test-app/app/src/main/java/com/tns/NativeScriptRuntime.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public static boolean reloadApplication() {
99
}
1010

1111
public static boolean reloadApplication(String baseDir) {
12-
return RuntimeHelper.reloadApplication();
12+
return RuntimeHelper.reloadApplication(baseDir);
1313
}
1414
}

test-app/app/src/main/java/com/tns/RuntimeHelper.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ public static Runtime initRuntime(Context context) {
245245
}
246246
}
247247

248+
// The overload is kept for API parity with ios, but not needed with android.
249+
public static synchronized boolean reloadApplication(String baseDir) {
250+
return reloadApplication();
251+
}
252+
248253
public static synchronized boolean reloadApplication() {
249254
final Context context = applicationContext;
250255
if (context == null || reloadScheduled) {
@@ -307,6 +312,12 @@ private static void waitForLiveSync(Context context) {
307312
}
308313

309314
private static void registerTimezoneChangedListener(Context context, final Runtime runtime) {
315+
// Register/unregister against the application context so the same Context
316+
// instance is used across initial launch and reload. Using the passed-in
317+
// context (which may be an Activity on first launch but applicationContext
318+
// on reload) would make unregisterReceiver fail and leak the old receiver.
319+
final Context receiverContext = applicationContext != null ? applicationContext : context;
320+
310321
IntentFilter timezoneFilter = new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED);
311322

312323
BroadcastReceiver timezoneReceiver = new BroadcastReceiver() {
@@ -339,14 +350,14 @@ public void onReceive(Context context, Intent intent) {
339350

340351
if (timezoneChangedReceiver != null) {
341352
try {
342-
context.unregisterReceiver(timezoneChangedReceiver);
353+
receiverContext.unregisterReceiver(timezoneChangedReceiver);
343354
} catch (IllegalArgumentException e) {
344355
// Already unregistered.
345356
}
346357
}
347358

348359
timezoneChangedReceiver = timezoneReceiver;
349-
context.registerReceiver(timezoneChangedReceiver, timezoneFilter);
360+
receiverContext.registerReceiver(timezoneChangedReceiver, timezoneFilter);
350361
}
351362

352363
public static void initLiveSync(Application app) {

0 commit comments

Comments
 (0)