Open jkasten2 opened 3 years ago
OneSignal.java
line 629 is already retrieving the Application Context from whatever context was passed in. So that means whoever calls OneSignal.startInit()
can pass in an Activity Context or Service Context. In other words, OneSignal.startInit()
can be called from any Activity or Service if necessary, and is not restricted to being called from Application.onCreate()
.
Many consumers of your library already subclass the Application
class for their own app specific initialization, and those who don't have their own Application
subclass can easily call OneSignal.startInit()
from their Activity or Service without issues. So is there really a problem that you're trying to solve here, or am I missing something ?
Motivation
OneSignal requires
OneSignal.initWithContext(context)
be called fromApplication.onCreate
. However there is no guarantee the app developer does this so the OneSignal SDK may not have aContext
instance. This has the following downsides:Application.onCreate
. This means SDK initialization is not very flexible.Context
is just half the problem,ActivityLifecycleCallbacks
have to be setup before any Activities are shown.null
Context
checks in our code. (one example)null
check much cleaner, but even better if we can remove all checks completely.null
Context
bugs in the SDK.Scope
Research and make note of options (even thoughts on things that don't work and why) to get an Application Context without requiring the developer to supply it.
ActivityLifecycleCallbacks
) while researching also make a note of this.Possible Options
LocalContext.current
, this might only work with Jetpack UI components and it seems it requires adding s@Composable
attribute to your method. Example codeContext
.Context
.ContentProvider
is designed for, but I think it is ok to use this way.