JacksOnF1re JacksOnF1re - 10 days ago 6
Android Question

Stop intent from beeing executed - in application subclass

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.

Answer

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.