[Solved] Why Do We Extend Application Class In Android [closed]


Android apps run properly even without extending it.

Android apps can run properly without extending it. They can run properly without extending Activity. You extend Application when it does something useful for you.

Can anyone explain this scenario as why exactly do we extend it.

It is used for per-process initialization that should always happen, not just for certain activities or other components.

So, for example, you might initialize:

  • Dependency injection (e.g., Dagger)
  • Crash logging (e.g., ACRA)
  • Diagnostic tools (e.g., LeakCanary, Stetho, Sonar)
  • Global pools (e.g., OkHttpClient)

Ideally, you initialize as little as possible, simply because this initialization is performed on the main application thread every time your process is forked. But, it is often convenient for things that should be set up before any of your application logic is executed.

3

solved Why Do We Extend Application Class In Android [closed]