Created
March 23, 2017 22:21
-
-
Save digitalbuddha/4f06fdf7fa2c6dcace7593abd32259ef to your computer and use it in GitHub Desktop.
GoodOrEvil pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Singleton | |
| public class ActivityNotLeakerISwear implements Application.ActivityLifecycleCallbacks { | |
| private static final Logger LOGGER = LoggerFactory.getLogger(URLHandler.class); | |
| @Nullable | |
| private Activity currentActivity; | |
| @Inject | |
| public ActivityNotLeakerISwear() { | |
| } | |
| public void startActivity(Intent intent) { | |
| if (currentActivity != null) { | |
| currentActivity.startActivity(intent); | |
| } | |
| } | |
| @Override | |
| public void onActivityCreated(Activity activity, Bundle savedInstanceState) { | |
| //onActivityCreated | |
| } | |
| @Override | |
| public void onActivityStarted(Activity activity) { | |
| //onActivityStarted | |
| } | |
| @Override | |
| public void onActivityResumed(Activity activity) { | |
| if (currentActivity == null || activity instanceof MainActivity || | |
| currentActivity instanceof IntentFilterActivity) { | |
| currentActivity = activity; | |
| } | |
| } | |
| @Override | |
| public void onActivityPaused(Activity activity) { | |
| //onActivityPaused | |
| } | |
| @Override | |
| public void onActivityStopped(Activity activity) { | |
| //onActivityPaused | |
| } | |
| @Override | |
| public void onActivitySaveInstanceState(Activity activity, Bundle outState) { | |
| //onActivitySaveInstanceState | |
| } | |
| @Override | |
| @SuppressWarnings("PMD.CompareObjectsWithEquals") | |
| public void onActivityDestroyed(Activity activity) { | |
| //please don't change the == to equals in here | |
| if (currentActivity == activity) { | |
| currentActivity = null; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment