2010-02-23 46 views

回答

0

你可以使用extras將它傳遞給intent對象。事情是這樣的

在非活性類創建的意圖後設置使用

objIntent.putExtra("keyName", "somevalue"); 

在活動類訪問它像這樣

Bundle extras = getIntent().getExtras(); 
if(extras !=null) 
{ 
String value = extras.getString("keyName"); 
} 

編輯值:

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); .. 
    } 
+0

謝謝,如何發送哈希表對象到活動類 – saravanan 2010-02-23 13:56:05

+0

即 class CityList extends活動DBConnection server = new DBConnection(); \t \t server.getDataValues(); \t \t嘗試{ \t \t \t Bundle extras = getIntent()。getExtras(); \t \t \t ArrayList list = extras.getStringArrayList(「city」); \t \t \t System.out.println(list.get(0)); \t \t \t System.out.println(list.get(1)); (例外e){ \t \t} catch(Exception e){ \t \t \t System.out.println(e.toString()); \t \t} } 類一個ServerConnection { .... 意圖意圖=新意圖(此,CityList.class); ArrayList list = new ArrayList (); \t \t \t list.add(「city_1」); \t \t \t list.add(「city_2」); \t \t \t intent.putStringArrayListExtra(「city」,list); .. } – saravanan 2010-02-23 14:20:41

+0

但igot空指針異常 – saravanan 2010-02-23 14:21:02