2017-02-26 91 views
-1


我想要一個的BluetoothSocket傳遞給活動與下面的代碼:
包裹:不能編組值android.bluetooth.BluetoothSocket

Intent intent = new Intent(getActivity(), ChatActivity.class); 
Bundle bundle = new Bundle(); 
ArrayList array = new ArrayList<BluetoothSocket>(); 
array.add(connectToDevice.getMmSocket()); 
bundle.putParcelableArrayList("Array", array); 
startActivity(intent, bundle); 

但是,當我嘗試從活動得到它我要開始用下面的代碼:

Bundle bundle = getIntent().getExtras(); 
Parcelable[] parceble = bundle.getParcelableArray("Array"); 
ArrayList<BluetoothSocket> array = new ArrayList<>(parceble.length); 
BluetoothSocket socket = array.get(0); 

我得到這個錯誤:

java.lang.RuntimeException: Parcel: unable to marshal value [email protected]` 

請幫幫我。 在此先感謝。

+0

您無法通過Intent傳遞此類。使服務和綁定活動內 – Selvin

+0

@Selvin \t 我該怎麼做?感謝您的耐心提前 –

回答

-1

使BluetoothSocket類實現Parcelable接口

+0

它已經實現了「可關閉」 –

+0

能夠編組值,你的班級應該實現parcelable接口 – Mohamed

+0

是不是有另一種方式將它傳遞給我的活動? –