I have a class that refers to UiApplication.getUiApplication() multiple times, would there be any performance benefit in assigning it to an instance like the following:
private UiApplication _uiApplication;
public MyClass()
{
_uiApplication = UiApplication.getUiApplication();
}
Or is calling UiApplication.getUiApplication() every time it is required exactly the same?
UiApplication.getUiApplication()retrieves the UiApplication instance from where the calling code is executing. So if you are calling it from your app, it will be the same as using a variable. But if you are calling it from code that executes inside another application (such as code insidePhoneListenercallbacks, or some other system hooks, or alternate entry points), then it will return a reference to that external application, or even null if there’s no GUI application. (Notice how you can write code in your BlackBerry project that executes in other processes. So don’t confuse application context -an executing app- with your application source code, which is your codebase inside a BlackBerry workspace).So, in general, for regular use inside your own app process, the only performance gain would be not making a method call, which is a ridiculous gain (unless you were calling from inside a loop). If anything, it is the programmer’s performance what increases as it has to type less.