1

Under some conditions, my application gets started by calling one of my Broadcast-Receivers or Services (etc), but I want to prevent the component that is used for the intent to get started.

Why: Because I need to do some prior initialization work do run, before any component should start. But this work can be a long running thing, therefore I can not just execute it inside of my application subclass on the main thread.

I am subclassing the Application in my app. Therefore my approach would be to somehow intervent the intent in the onCreate() of my application subclass and instead, start a specific service of mine, which runs the prior-initialization and re-calls the intent, that was intentionally used after that.

Can you image any possibly do get this done? Thank you!

Ps.: I have a lot components that could possibly start my application. I do not want to include my condition-code inside of every component.

JacksOnF1re
  • 3,336
  • 24
  • 55

1 Answers1

1

but I want to prevent the component that is used for the intent to get started.

Other than crashing your app, this is not possible. And, even then, the component would never be started.

Therefore my approach would be to somehow intervent the intent in the onCreate() of my application subclass and instead, start a specific service of mine, which runs the prior-initialization and re-calls the intent, that was intentionally used after that.

Short of a custom ROM with a custom framework implementation, this is not possible. You do not have access to the information that you need, nor do you have any means of stopping the component.

And, if you are in a case where a custom ROM is a possibility, move this initialization work to a core OS process (i.e., not an Android SDK app, but a standard Linux process started at boot time), and have your app use IPC to get this data.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Sad. I wonder how am I supposed to do long running migrations or internal "app-data-updates" (like sql data things), before anything else starts. I am afraid there is no other possibly as to subclass all of my components and let them inherit the initialization checks. – JacksOnF1re Nov 28 '16 at 17:06
  • @JacksOnF1re: You do that work earlier. For example, suppose you ship an app update with a significant schema change, one that will require a chunk of time to complete. You kick off that work as soon as the update is installed. Particularly for users who opt into auto-updates, the work is likely to be completed long before anything else of your app gets invoked. You should not need to subclass anything new, as you already have those classes. Your initialization logic can reside in a separate utility class, not a base component class. – CommonsWare Nov 28 '16 at 17:24