Start a new topic

Passing data from Activity to JS

Hi, 

I'm very new to Wikitude API.
Just wondering how could I pass my data (from my MainActivity) to Javascript so it could use it to filter the results that it obtained from the database and use it to load the POI accordingly.  

Please provide a detail guidance as I'm really new in this. 

Thanks in advance. 


Hello Jacob,

Please have a look at the documentation here.

Thanks
Eva

 

I have tried but still unable to pass data
My AR Activity
@Override
protected void onPostCreate(Bundle savedInstanceState){
super.onPostCreate(savedInstanceState);

architectView.onPostCreate();
try{
final JSONArray jsonArray = generateUserInformation(LoginActivity.user);
this.architectView.load("file:///android_asset/detail/index.html");
this.architectView.callJavascript("World.loadUserFromJsonData(" + jsonArray.toString() + ")");
} catch (Exception e){

}
} My Javascript
loadUserFromJsonData: function loadUserFromJsonDataFn(userData) {
var user = userData.user;
}
Hello Jacob,

There are a couple of errors in your code. First of all, since the calls are asynchronous in javascript, it could be that you are calling the callJavascript method before the loading of the index.html file is completed. Therefore, I would suggest you move the callJavascript method outside of the onPostCreate (maybe put it in the onArchitect World loaded function). Second of all, make sure that the LadUserFromJsonData is actually a function inside the World, otherwise the line below is wrong
loadUserFromJsonData: function loadUserFromJsonDataFn(userData) {
Thanks
Eva
Login or Signup to post a comment