1# Starting SystemUI CoreStartables 2 3## Overview 4 5A [CoreStartable](/packages/SystemUI/src/com/android/systemui/CoreStartable.java) class represents 6a chunk of SystemUI functionality that is initialized at startup time, independent of the rest of 7the system. Which CoreStartables are included and run can be customized per-build via Dagger. 8 9The base class contains nominal functionality, making it lightweight and inexpensive to construct. 10Unlike Activities, Services, and similar Android constructs, CoreStartables do not have unique 11context, and have no lifecycle methods except for a singular `#start` method that is called once. 12 13## How to Define a CoreStartable 14 151) Subclass `CoreStartable`. Put any initialization logic in its `#start` method. Preferably, put it 16 in its own source package (with related code) to keep it organizationally distinct from other 17 code in SystemUI. 18 192) Mark its class with `@SysUISingleton` and its constructor with `@Inject`. 20 213) Define a corresponding Dagger module in the same package. The name of the module should follow 22 the pattern: “Start<Feature>Module” where <Feature> is replaced with the name of the 23 CoreStartable. 24 254) Put the following definition inside your new module: 26 27```java 28 @Binds 29 @IntoMap 30 @ClassKey(Feature.class) 31 abstract CoreStartable bindFeature(Feature impl); 32``` 33 345) Include the new module in any clients that may need it. For AOSP, this is the 35 SystemUICoreStartableModule. 36 37## Tips and Tricks 38 39**CoreStartables should be single-feature focused.** If you need something run at startup time 40that doesn't have a clear initialization path in existing code, strongly consider defining a _new_ 41CoreStartable instead of inserting into a random place in an existing one. 42 43**CoreStartables should be order independent.** They currently are started in an arbitrary but 44deterministic order. We do not promise that this order won't change in the future, however. We do 45not provide a mechanism for changing the order. If you need some other part of the system to 46come online first, consider adding a listener to that part of the system.