+

Search Tips   |   Advanced Search

Add custom code to an Android app

Add custom code to the Android app in the onCreate method is deprecated. To add custom code to the Android app, use the onWLInitCompleted method.

Since IBM Worklight V5.0.6, add custom code to the onWLInitCompleted method. The onWLInitCompleted method is invoked when the MobileFirst initialization process is complete and the client is ready.

In IBM Worklight V5.0.5 and earlier, custom code was added to the onCreate method. However, since IBM Worklight V5.0.6, adding custom code to the onCreate method is deprecated. Support might be removed in any future version.

If we migrate an existing Android app to IBM Worklight V5.0.6, any custom code in the onCreate method is automatically moved to the onWLInitCompleted method during the migration process. A comment is also added to indicate that the code was moved.

The following code snippet is an example of a new application:

Figure 1. Custom code in a new application

public class b extends WLDroidGap {
  
  @Override
  public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
  
  /**
     * onWLInitCompleted is called when the Worklight runtime framework initialization is complete.
     */
  @Override
  public void onWLInitCompleted(Bundle savedInstanceState){
    super.loadUrl(getWebMainFilePath());
    // Add custom initialization code after this line
}

The following code snippet is an example of a migrated application:

Figure 2. Custom code in a migrated application

@Override
  public void onWLInitCompleted(Bundle savedInstanceState) {
     //Additional initialization code from onCreate() was moved here       super.loadUrl(getWebMainFilePath());
  @Override
  public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     //Additional initialization code was moved to onWLInitCompleted().
  }


Parent topic: Develop hybrid applications for Android