{ "id": "70657", "key": "TIMOB-4341", "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": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2019-11-20T23:14:34.000+0000", "created": "2011-06-07T07:28:44.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "tbs-1.9.0" ], "versions": [ { "id": "11244", "name": "Release 1.7.0", "archived": true, "released": true, "releaseDate": "2011-06-13" } ], "issuelinks": [ { "id": "12387", "type": { "id": "10020", "name": "Depends", "inward": "is dependent of", "outward": "depends on" }, "outwardIssue": { "id": "79201", "key": "TIMOB-4991", "fields": { "summary": "Android: Call module's onAppCreate method as part of application's onCreate processing", "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": "Critical", "id": "1" }, "issuetype": { "id": "2", "description": "A new feature of the product, which has yet to be developed.", "name": "New Feature", "subtask": false } } } } ], "assignee": null, "updated": "2019-11-20T23:14:34.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": "The latest version of the Urban Airship SDK supports a new notification handling process, whereby the PushService can be configured to run in a separate process. When it is configured in that manner it creates a 2nd instance of the application which in turn results in the OnCreate method of TiApplication being called a 2nd time. The result is a NullPointerException occurring somewhere in that method.\r\n\r\nThe workaround for now is to configure the PushService to run within the current application process, but UA recommends running it in a separate process to conserve memory.\r\n\r\nThe following excerpt is from the Urban Airship documentation on how to resolve this issue:\r\n\r\n\r\nProcess Management\r\n\r\nIt is possible to run the push service either in your application process or as a separate stand-alone process. We recommend that most applications run it in a separate process. The primary benefit to this approach is that it allows the service to run with a relatively small memory footprint even if your application is resource intensive. In a low memory situation the OS can kill a backgrounded application's main process without disrupting the service.\r\n\r\nTo run the service in a separate process, simply add the \"android:process\" attribute to the service element and provide a name for the process. If the name starts with a colon, the process will be private to your application:\r\n\r\n\r\nNote that when the service runs in a separate process it will create a separate instance of the application when the service is started. This means that your application's onCreate() method will be called again in another context. For most applications this is not an issue, but if the onCreate method invokes any code that should only be called once (such as analytics code that changes state outside of the application) you will want to ensure that it only runs in one of the processes. The following sample illustrates a method for determining which process your application is running within:\r\n\r\npublic class MyApplication extends Application {\r\n public void onCreate() {\r\n // the main process for this application is named for the package\r\n // if this is the default process, run some special code\r\n if (isProcess(context.getPackageName()) {\r\n //run default process operations here\r\n }\r\n }\r\n\r\n private boolean isProcess(String processName) {\r\n Context context = getApplicationContext();\r\n ActivityManager actMgr = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);\r\n List appList = actMgr.getRunningAppProcesses();\r\n for (RunningAppProcessInfo info : appList) {\r\n if (info.pid == android.os.Process.myPid() && processName.equals(info.processName)) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n}\r\n", "attachment": [], "flagged": false, "summary": "2nd instance of application run from a separate process causes NullPointerException", "creator": { "name": "jenglish", "key": "jenglish", "displayName": "Jeff English", "active": true, "timeZone": "America/Chicago" }, "subtasks": [], "reporter": { "name": "jenglish", "key": "jenglish", "displayName": "Jeff English", "active": true, "timeZone": "America/Chicago" }, "environment": null, "comment": { "comments": [ { "id": "157701", "author": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "body": "The [service-in-a-separate-process suggestion by UrbanAirship|http://urbanairship.com/docs/android-client-push.html#advanced-setup] requires some fairly major architectural changes and considerations which we're deferring for consideration in 1.9. A few points:\r\n\r\n* It creates a second instance of the Titanium application but doesn't run through the root activity, thus no titanium javascript code has an opportunity to run. Because of that, there's no opportunity to call {{takeOff}} via JS.\r\n\r\n* In that second instance, our Java UrbanAirship module instance wouldn't be instantiated yet either, as the instantiation occurs via {{bootModules}}, which gets invoked only when a KrollContext is created (which only happens via our normal startup via the root activity).\r\n\r\n* The UA notification callback (a JS function) is meanwhile hanging around in the first application instance's UrbanAirship module instance. So it anyway can't be called via the second instance.\r\n\r\n", "updateAuthor": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "created": "2011-06-23T15:50:33.000+0000", "updated": "2011-06-23T15:50:33.000+0000" }, { "id": "162797", "author": { "name": "jenglish", "key": "jenglish", "displayName": "Jeff English", "active": true, "timeZone": "America/Chicago" }, "body": "With the fix for TIMOB-4991 and MOD-157, this issue should be resolved. Initial testing of the fix for MOD-157 with a hand-coded fix for TIMOB-4991 shows that running UA in a separate process works. Awaiting official fix for TIMOB-4991 to do final validation.", "updateAuthor": { "name": "jenglish", "key": "jenglish", "displayName": "Jeff English", "active": true, "timeZone": "America/Chicago" }, "created": "2011-08-15T06:57:25.000+0000", "updated": "2011-08-15T06:57:25.000+0000" }, { "id": "452836", "author": { "name": "ahutton", "key": "ahutton", "displayName": "Alan Hutton", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Should have been closed per dev comments. Closing.", "updateAuthor": { "name": "ahutton", "key": "ahutton", "displayName": "Alan Hutton", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-11-20T23:14:34.000+0000", "updated": "2019-11-20T23:14:34.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }