Skip to content

Commit 80cfbce

Browse files
committed
chore: pr comments
1 parent caae42d commit 80cfbce

3 files changed

Lines changed: 18 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) {

test-app/runtime/src/main/cpp/com_tns_Runtime.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ extern "C" JNIEXPORT void Java_com_tns_Runtime_WorkerGlobalOnMessageCallback(JNI
357357
auto runtime = TryGetRuntime(runtimeId);
358358
if (runtime == nullptr) {
359359
// TODO: Pete: Log message informing the developer of the failure
360+
return;
360361
}
361362

362363
auto isolate = runtime->GetIsolate();
@@ -375,6 +376,7 @@ extern "C" JNIEXPORT void Java_com_tns_Runtime_WorkerObjectOnMessageCallback(JNI
375376
auto runtime = TryGetRuntime(runtimeId);
376377
if (runtime == nullptr) {
377378
// TODO: Pete: Log message informing the developer of the failure
379+
return;
378380
}
379381

380382
auto isolate = runtime->GetIsolate();
@@ -440,6 +442,7 @@ extern "C" JNIEXPORT void Java_com_tns_Runtime_ClearWorkerPersistent(JNIEnv* env
440442
auto runtime = TryGetRuntime(runtimeId);
441443
if (runtime == nullptr) {
442444
// TODO: Pete: Log message informing the developer of the failure
445+
return;
443446
}
444447

445448
auto isolate = runtime->GetIsolate();
@@ -458,6 +461,7 @@ extern "C" JNIEXPORT void Java_com_tns_Runtime_CallWorkerObjectOnErrorHandleMain
458461
auto runtime = TryGetRuntime(runtimeId);
459462
if (runtime == nullptr) {
460463
// TODO: Pete: Log message informing the developer of the failure
464+
return;
461465
}
462466

463467
auto isolate = runtime->GetIsolate();

0 commit comments

Comments
 (0)