I am developing an Android app with jQuery Mobile and PhoneGap. This is my activity:
public class xxx extends DroidGap {
/** Called when the activity is first created. */
private String FILENAME = "";
private static final String HTML_ROOT = "file:///android_asset/www/";
private Handler handler = null;
private static WebView webView = null;
public MyTeam team = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
handler = new Handler();
FILENAME = getString(R.string.fileName);
//parsing data from file
String json = readFile();
team = parseJson(json);
appView.addJavascriptInterface(this, "MyTeam");
super.loadUrl("file:///android_asset/www/menu.html");
}
public String HW(){
return team.getTeamName();
}
And this is my Javascript code in menu.html:
$(document).ready(function(){
alert(MyTeam.HW()); // work perfectly
alert("name "+MyTeam.team.getTeamName()); //doesn't work!
});
So the problem is:
- I can access the HW function that returns me team.getTeamName();
- I don't have access to the team variable name in my activity because MyTeam.team.getTeamName() doesn't work.
It seems that I can access only functions but not directly public variables.
What I am doing wrong?
Thanks.