Project: titanium
Issue TIMOB-15443: Android: Allow full Activity lifecycle access for Titanium modules
The current Android module API offers access to the *application* lifecycle, but this is mostly irrelevant for Android (it's the iOS model!), where code needs access to the *Activity* lifecycle (i.e. onCreate, onResume, onPause, onStop, onDestroy, onActivityResult). A good example is this class in the Facebook SDK: https://developers.facebook.com/docs/reference/android/current/UiLifecycleHelper Currently, this class cannot be used in module code that runs in the context of a Window or TabGroup, since the module does not have access to that Activity's lifecycle events. This greatly complicates module porting to Titanium, since using such classes requires creating non-UI activities, and then we need methods to sync between the various Activities. h3. Proposal # Add a new dictionary parameter to Ti.UI.createWindow and createTabGroup, attachAndroidModule: 'modulename' # If attachAndroidModule is specified, the module is loaded prior to Activity creation and its lifecycle events correspond to those of the created UI Activity. # The Javascript does not change - the module is "required" and used as before. # Clearly the module can be attached to multiple Activities in a Titanium app - just as an Android library can be used by multiple Activities in in a native Android app, and in each case the events correspond to the Activity in use. # I would deprecate the current lifecycle events in the Android module, since they're confusing in the Android context. However, if desired, I suppose it's possible to maintain "legacy" module behavior (per module) through tiapp.xml configuration parameters. This is yet another stumbling block to easy porting of 3rd party code. The Titanium community would greatly benefit from this improvement.
Story points: 13