@@ -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