OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.base; | 5 package org.chromium.base; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.Application; | 8 import android.app.Application; |
9 import android.app.Application.ActivityLifecycleCallbacks; | 9 import android.app.Application.ActivityLifecycleCallbacks; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 | 386 |
387 /** | 387 /** |
388 * Unregisters the given listener from receiving state changes. | 388 * Unregisters the given listener from receiving state changes. |
389 * @param listener Listener that doesn't want to receive state changes. | 389 * @param listener Listener that doesn't want to receive state changes. |
390 */ | 390 */ |
391 public static void unregisterApplicationStateListener(ApplicationStateListen er listener) { | 391 public static void unregisterApplicationStateListener(ApplicationStateListen er listener) { |
392 sApplicationStateListeners.removeObserver(listener); | 392 sApplicationStateListeners.removeObserver(listener); |
393 } | 393 } |
394 | 394 |
395 /** | 395 /** |
396 * Robolectric JUnit tests create a new application between each test, while all the context | |
397 * in static classes isn't reset. This function allows to reset the applicat ion status to avoid | |
398 * being in a dirty state. | |
399 */ | |
400 public static void destroyForJUnitTests() { | |
401 sApplicationStateListeners.clear(); | |
402 sGeneralActivityStateListeners.clear(); | |
403 sActivityInfo.clear(); | |
404 sCachedApplicationState = 0; | |
Torne
2015/11/25 19:10:52
You should update this holding the lock (because *
dgn
2015/11/25 19:53:04
Thanks, that was bad :/ Done.
| |
405 sActivity = null; | |
406 sApplication = null; | |
407 sNativeApplicationStateListener = null; | |
408 } | |
409 | |
410 /** | |
396 * Registers the single thread-safe native activity status listener. | 411 * Registers the single thread-safe native activity status listener. |
397 * This handles the case where the caller is not on the main thread. | 412 * This handles the case where the caller is not on the main thread. |
398 * Note that this is used by a leaky singleton object from the native | 413 * Note that this is used by a leaky singleton object from the native |
399 * side, hence lifecycle management is greatly simplified. | 414 * side, hence lifecycle management is greatly simplified. |
400 */ | 415 */ |
401 @CalledByNative | 416 @CalledByNative |
402 private static void registerThreadSafeNativeApplicationStateListener() { | 417 private static void registerThreadSafeNativeApplicationStateListener() { |
403 ThreadUtils.runOnUiThread(new Runnable() { | 418 ThreadUtils.runOnUiThread(new Runnable() { |
404 @Override | 419 @Override |
405 public void run() { | 420 public void run() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 | 459 |
445 if (hasPausedActivity) return ApplicationState.HAS_PAUSED_ACTIVITIES; | 460 if (hasPausedActivity) return ApplicationState.HAS_PAUSED_ACTIVITIES; |
446 if (hasStoppedActivity) return ApplicationState.HAS_STOPPED_ACTIVITIES; | 461 if (hasStoppedActivity) return ApplicationState.HAS_STOPPED_ACTIVITIES; |
447 return ApplicationState.HAS_DESTROYED_ACTIVITIES; | 462 return ApplicationState.HAS_DESTROYED_ACTIVITIES; |
448 } | 463 } |
449 | 464 |
450 // Called to notify the native side of state changes. | 465 // Called to notify the native side of state changes. |
451 // IMPORTANT: This is always called on the main thread! | 466 // IMPORTANT: This is always called on the main thread! |
452 private static native void nativeOnApplicationStateChange(int newState); | 467 private static native void nativeOnApplicationStateChange(int newState); |
453 } | 468 } |
OLD | NEW |