{ "id": "171953", "key": "TIMOB-26228", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2018-07-25T01:50:41.000+0000", "created": "2018-07-22T13:48:45.000+0000", "priority": { "name": "Critical", "id": "1" }, "labels": [ "android" ], "versions": [], "issuelinks": [ { "id": "56699", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "inwardIssue": { "id": "171973", "key": "TIMOB-26240", "fields": { "summary": "Android: Remove harmless activity errors/warnings logged on startup", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "priority": { "name": "Medium", "id": "3" }, "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "subtask": false } } } } ], "assignee": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2018-08-06T17:37:03.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "I have a module where I want to configure an SDK by passing the current activity to it automatically on app start. We have the {{onCreate}} method via the {{@Kroll.onCreate}} annotation, but neither of the following methods worked there:\r\n- {{getActivity()}} (because of the static context)\r\n- {{TiApplication.getAppRootOrCurrentActivity()}} errors: \r\n{quote}\r\nNo valid root or current activity found for application instance\r\n{quote}\r\n- TiApplication.getInstance().getCurrentActivity(): Same as above\r\n\r\nI also tried invoking them in the constructor of the module but that did not work either. I am trying to prevent a manually {{initialize()}} call from the module, so I am wondering if there is a better approach here.", "attachment": [], "flagged": false, "summary": "Android: Cannot get current activity in native module when using 7.3.0+", "creator": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "environment": "SDK 7.3.0", "comment": { "comments": [ { "id": "439395", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "Update: It seems to not crash with:\r\n{code:java}\r\n\t@Override\r\n\tpublic void onStart(Activity activity) {\r\n\t\t// Use \"activity\" from here\r\n\t}\r\n{code}\r\nBut it still logs this:\r\n{code}\r\n[ERROR] TiApplication: (main) [817,864] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [2,866] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [9,875] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [5,880] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [1,881] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [1,882] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [3,885] No valid root or current activity found for application instance\r\n[WARN] TiAndroid: (main) [1,886] Application instance no longer available. Unable to get current activity.\r\n[ERROR] TiApplication: (main) [1,887] No valid root or current activity found for application instance\r\n[WARN] TiAndroid: (main) [1,888] Application instance no longer available. Unable to get current activity.\r\n[WARN] TiAndroid: (main) [0,888] Application instance no longer available. Unable to get current activity.\r\n[ERROR] TiApplication: (main) [4,892] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [7,899] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [2,901] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [1,902] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [0,902] No valid root or current activity found for application instance\r\n{code}\r\n\r\nUpdate 2: It actually works fine in SDK 7.2.0 and does not any warning. Considering this a 7.3.0 regression, updating the ticket accordingly.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-07-22T14:11:41.000+0000", "updated": "2018-07-22T14:27:08.000+0000" }, { "id": "439455", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Titanium does not have a Java {{@Kroll.onCreate}} annotation.\r\nPerhaps you mean {{@Kroll.onAppCreate}} instead?\r\n\r\nIf so, then that method will be called when the Android Java {{Application}} instance gets created during a cold-start, but before an Android {{Activity}} gets created. This is by Google's design, not ours. You cannot fetch an {{Activity}} on app startup because no UI has been created yet. So, yes, the getters for an activity should return {{null}} at this point. This is the correct behavior.\r\n\r\nWhat you can do instead is override the Java {{KrollModule.onStart(Activity)}} method like [~hknoechel] has suggested.\r\nhttps://docs.appcelerator.com/module-apidoc/latest/android/org/appcelerator/kroll/KrollModule.html#onStart(android.app.Activity)\r\n\r\nAlternatively, only call the {{TiApplication.getAppRootOrCurrentActivity()}} when your module's APIs have been called by JavaScript. An activity is guaranteed to be available then because the JavaScript runtime is created when the splash screen activity gets displayed. The splash screen activity hosts the JavaScript runtime and when you close all activities the JavaScript runtime is terminated. So, this is the best solution.", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-07-25T01:14:51.000+0000", "updated": "2018-07-25T01:14:51.000+0000" }, { "id": "439457", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This is not a regression. The warnings on startup are harmless. We've reduced the number of warnings on app startup in Titanium 7.4.0. We'll look into getting rid of the rest of the false-positive warnings in the future.", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-07-25T01:50:20.000+0000", "updated": "2018-07-25T01:50:20.000+0000" }, { "id": "439464", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "[~jquick] I am not feeling good resolving this already. I just tested a few of my other modules and they also spit out the error when accessing our activity and they are not called from {{onCreate}}:\r\n{code}\r\n[ERROR] TiApplication: (main) [480,515] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [2,517] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [10,527] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [5,532] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [2,534] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [1,535] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [2,537] No valid root or current activity found for application instance\r\n[WARN] TiAndroid: (main) [1,538] Application instance no longer available. Unable to get current activity.\r\n[ERROR] TiApplication: (main) [0,538] No valid root or current activity found for application instance\r\n[WARN] TiAndroid: (main) [0,538] Application instance no longer available. Unable to get current activity.\r\n[WARN] TiAndroid: (main) [0,538] Application instance no longer available. Unable to get current activity.\r\n[ERROR] TiApplication: (main) [1,539] No valid root or current activity found for application instance\r\n[WARN] ContextImpl: Failed to ensure /dev/null/Android/data/com.appc.firebasedemo/cache: 400\r\n[ERROR] TiApplication: (main) [9,548] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [1,549] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [0,549] No valid root or current activity found for application instance\r\n[ERROR] TiApplication: (main) [1,550] No valid root or current activity found for application instance\r\n{code}", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-07-25T06:12:44.000+0000", "updated": "2018-07-25T06:12:44.000+0000" }, { "id": "439923", "author": { "name": "emerriman", "key": "emerriman", "displayName": "Eric Merriman ", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Closing as invalid. If incorrect, please reopen.", "updateAuthor": { "name": "emerriman", "key": "emerriman", "displayName": "Eric Merriman ", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-08-06T17:37:03.000+0000", "updated": "2018-08-06T17:37:03.000+0000" } ], "maxResults": 6, "total": 6, "startAt": 0 } } }