IBM Worklight v5.0.5 > Develop IBM Worklight applications > Development guidelines for mobile environments > Web and native code in iPhone, iPad, and Android

Receive data from the web view in a Java page


Implement this page as an Activity object or extend an Activity. Declare this activity in AndroidManifest.xml.

To receive data from the calling web view, use the Intent object defined on the native Activity. The IBM Worklight client framework makes the data available to the Activity in a Bundle.

// Send data from web view to the native Activity

WL.NativePage.show('com.example.android.tictactoe.library.GameActivity', 
                    this.callback, {"gameLevel":1,"playerName":"john",isKeyboardEnable:false});

// Receive the data in the native Activity

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);

    //Read int value, default = 0
    Integer gameLevel = getIntent().getIntExtra("gameLevel", 0);

    //Read String value
    String playerName = getIntent().getStringExtra("playerName");

    //Read boolean value, default = false
    Boolean isKeyboardEnable = getIntent().getBooleanExtra("isKeyboardEnable", false);
}


Parent Web and native code in iPhone, iPad, and Android


Related information:

http://developer.android.com/reference/android/content/Intent.html

http://developer.android.com/reference/android/app/Activity.html

http://developer.android.com/reference/android/os/Bundle.html





+

Search Tips   |   Advanced Search