Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17747] Android: Native module onStart() lifecycle method never called for Alloy project

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDone
Resolution Date2015-06-17T02:59:39.000+0000
Affected Version/sRelease 3.3.0
Fix Version/sRelease 4.1.0
ComponentsAndroid
LabelsTCSupport
ReporterJames Falkner
AssigneeIngo Muschenetz
Created2014-08-05T18:32:19.000+0000
Updated2017-03-16T21:42:48.000+0000

Description

Problem Description

I have created a native module that has some code in an onStart() method - when importing this module in my alloy controller using require(), the onStart() method is called when the root activity is started when using Titanium SDK 3.2.3.GA, but when using 3.3.0, it is never called. I have properly declared the module in my tiapp.xml and my onStart() method is pretty simple: {noformat} @Override public void onStart(Activity activity) { // This method is called when the module is loaded and the root context is started Log.d(TAG, "[MODULE LIFECYCLE EVENT] start"); super.onStart(activity); } {noformat} In 3.2.3.GA I see the debug message in the logcat output - but using 3.3.0.GA I never see it (however I do see the onPause and onStop lifecycle methods are properly called. My native module depends on some initialization code in onStart that cannot be moved to onAppCreate, so it's currently failing as onStart is never called (nor is onPause which is a bit suspect). Also, for a non-Alloy app, this does not happen -- all of the lifecycle methods, including onStart are called as expected.

Steps to reproduce.

1. Download the module from this [link](https://github.com/jamesfalkner/liferay-android-beacons/blob/master/dist/com.liferay.beacons-android-0.1.zip) 2. Create a titanium classic project 3. Paste this code:
var win = Ti.UI.createWindow({
    backgroundColor:'white'
});
var label = Ti.UI.createLabel();
win.add(label);
win.open();
 
if (Ti.Platform.name == "android") {
    var mod = require('com.liferay.beacons');
    label.text = "module is => " + mod + "and checkAvailability says: " + mod.checkAvailability();
} else {
    label.text = "liferay.beacons not supported on " + Ti.Platform.name;
}

Steps to reproduce the issue with alloy (which is easier to reproduce)

1. Create a new alloy project 2. Paste this to index.js:
var mod = require('com.liferay.beacons');
$.label.text= "module is => " + mod + "and checkAvailability says: " + mod.checkAvailability();
function doClick(e) {
    alert($.label.text);
}
 
$.index.open();
3. Run it in a device.

Comments

  1. Mauro Parra-Miranda 2014-08-10

    Hello, just to summarize (and correct me if I'm wrong): The onStart works: 3.2.3+Classic - OK 3.2.3+Alloy - OK 3.3.0+Classic - OK 3.3.0+Alloy - FAIL. Do you agree? Best Regards
  2. James Falkner 2014-08-10

    Yep, that's right :)
  3. Joe Falcone 2014-08-30

    We've observed the same thing with "Classic" projects and 3.3.0 - it depends on the complexity of app.js, which modules are loaded, etc. If I take one of our apps, and strip it down to the basics, I can get the onStart event. If I add everything back plus modules, I don't.
  4. Joe Falcone 2014-08-30

    Likewise with onCreate if you're looking for that event. Used to get it in 3.2.x SDK, not in 3.3.0.
  5. Federico Casali 2014-12-09

  6. Ashraf Abu 2015-06-11

  7. Ashraf Abu 2015-06-17

    To create a module that hooks to the lifecycle, take a look at here: https://github.com/appcelerator-modules/ti.facebook/blob/master/android/src/facebook/ActivityWorkerProxy.java And create the proxy as mentioned
    win1.fbProxy = fb.createActivityWorker({lifecycleContainer: win1});
    Hopefully this no longer is an issue and I'll close this as resolved. If this is still posing a problem, do comment.
  8. Lee Morris 2017-03-16

    Can confirm that this was done.

JSON Source