[TIMOB-26240] Android: Remove harmless activity errors/warnings logged on startup
| GitHub Issue | n/a |
|---|---|
| Type | Improvement |
| Priority | Medium |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2018-07-31T17:07:41.000+0000 |
| Affected Version/s | Release 7.3.0 |
| Fix Version/s | Release 7.3.0 |
| Components | Android |
| Labels | android, log |
| Reporter | Joshua Quick |
| Assignee | Joshua Quick |
| Created | 2018-07-27T02:11:09.000+0000 |
| Updated | 2018-08-03T18:27:52.000+0000 |
Description
*Summary:*
A Titanium 7.3.0 built Android app will log the following messages on startup.
[ERROR] : TiApplication: (main) [806,864] No valid root or current activity found for application instance
[ERROR] : TiApplication: (main) [3,867] No valid root or current activity found for application instance
[ERROR] : TiApplication: (main) [25,892] No valid root or current activity found for application instance
[ERROR] : TiApplication: (main) [13,905] No valid root or current activity found for application instance
[ERROR] : TiApplication: (main) [4,909] No valid root or current activity found for application instance
[ERROR] : TiApplication: (main) [1,910] No valid root or current activity found for application instance
[ERROR] : TiApplication: (main) [3,913] No valid root or current activity found for application instance
[WARN] : TiAndroid: (main) [2,915] Application instance no longer available. Unable to get current activity.
[ERROR] : TiApplication: (main) [1,916] No valid root or current activity found for application instance
[WARN] : TiAndroid: (main) [1,917] Application instance no longer available. Unable to get current activity.
[WARN] : TiAndroid: (main) [0,917] Application instance no longer available. Unable to get current activity.
[ERROR] : TiApplication: (main) [2,919] No valid root or current activity found for application instance
[ERROR] : TiApplication: (main) [6,925] No valid root or current activity found for application instance
[ERROR] : TiApplication: (main) [1,926] No valid root or current activity found for application instance
[ERROR] : TiApplication: (main) [2,928] No valid root or current activity found for application instance
[ERROR] : TiApplication: (main) [2,930] No valid root or current activity found for application instance
These errors/warnings are actually harmless noise triggered by Titanium when loading its core modules (ie: Ti, Ti.UI, Ti.Platform, etc.) when the Android Application instance gets created, but before an Activity has been created. There is no Activity to fetch at this point in the code and the modules already correctly handle null and will fetch a valid Activity later when needed.
*Recommended Solution:*
It's the responsibility of the caller to handle the null case, not the method.
So, remove the "Application instance no longer available." log message in AndroidModule.getCurrentActivity() here...
https://github.com/appcelerator/titanium_mobile/blob/7_3_X/android/modules/android/src/java/ti/modules/titanium/android/AndroidModule.java#L580
And remove the "No valid root or current activity found for application instance" log message from TiApplication.getRootOrCurrentActivity() here...
https://github.com/appcelerator/titanium_mobile/blob/7_3_X/android/titanium/src/java/org/appcelerator/titanium/TiApplication.java#L297
*Side Note:*
The TiApplication.getInstance() call can never return null. The Android Application class is always the 1st object to be created within the app and is guaranteed to exist for the lifetime of the app. There is no point in doing a null check on it. Nor do we need to keep a weak reference to it within TiApplication. A normal strong reference will suffice.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/10219 PR (7.3.X): https://github.com/appcelerator/titanium_mobile/pull/10220
Verified the fix in SDK 7.3.0.v20180803101103 & 7.4.0.v20180803013445. Closing.