2017-07-22 212 views
-1

// ListSalesItemActivity(這是列表視圖的活動,當我點擊一個項目上市,我會去ViewDetailActivity與顯示DATAS)無法傳遞對象到另一個對象的Android活動(與parcelable)

我能獲取數據,但不能傳遞到另一個acticity和應用程序將停止

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_list_sale_item); 

    myContext = this; 


    salesLV = (ListView) findViewById(R.id.salesLV); 


    salesLV.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

      Bundle bundle = new Bundle(); 


      Intent myIntent = new Intent(ListSaleItemActivity.this, SaleDetailActivity.class); 

      SaleObject SO = mc.SalesObjectList(getApplicationContext()).get(position); 
      Log.d("myTag", SO.getStrName());//able to get name 
      bundle.putString("Name", SO.getStrName()); 
      myIntent.putExtras(bundle); 
      startActivity(myIntent); 


     } 
    }); 

} 

// ViewDetailActivity

Intent i = getIntent(); 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_sale_detail); 
    { 

     Bundle bd = i.getExtras(); 
     String name = bd.getString("Name"); 
     Log.d("myTag", name);//does not print anything in logcat and application stopped. 

     //I tried this and also does not work 
     /*if(bd != null) 
     { 
      String getName = (String) bd.get("Name"); 
      Log.d("myTag", getName); 
     }else{ 
      Log.d("myTag", "1"); 
     }*/ 

    } 
} 
+0

很容易前找出錯誤都要經過編碼,如果你有張貼日誌(錯誤報告) –

回答

0

認沽I = getIntent();在onCreate()中。

Intent i; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_sale_detail); 
{ 

    i = getIntent(); 
    Bundle bd = i.getExtras(); 
    String name = bd.getString("Name"); 
    Log.d("myTag", name); 

} 

}

相關問題