how to get the hashtable object form a class to activity in android
I want开发者_如何学JAVA to get the hashtable object from non activity class to activity class an android
please reply to me
thanks
you can pass it through the intent object using extras. Something like this
after creating the intent in your non-activity class set the value using
objIntent.putExtra("keyName", "somevalue");
In the activity class access it like this
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
String value = extras.getString("keyName");
}
EDIT:
CityList extends Activity {
DBConnection server = new DBConnection();
server.getDataValues();
try {
Bundle extras = getIntent().getExtras();
ArrayList<String> list = extras.getStringArrayList("city");
System.out.println(list.get(0));
System.out.println(list.get(1)); }
catch(Exception e) { Log.d(this.getClass(), e.getMessage()); }
}
class ServerConnection {
.... Intent intent = new Intent(this, CityList.class);
ArrayList<String> list = new ArrayList<String>();
list.add("city_1");
list.add("city_2");
intent.putStringArrayListExtra("city", list); ..
}
精彩评论