Is it possible to save BluetoothSocket object using shared preference in android . I got the reference from this How Android SharedPreferences save/store object ,and saved the object using this reference. My problem is that i can not retrieve the object as BluetoothSocket.
This is my code for saving
void saveBluetoothDevice(String connectingDevice)
{
    SharedPreferences.Editor editor = getSharedPreferences(Prefer_Bluetooth_name, MODE_PRIVATE).edit();
    Gson gson = new Gson();
    editor.putString("name", connectingDevice);
    String json = gson.toJson(mmDevice);
    editor.putString("MyObject", json);
    //editor.putInt("idName", 12);
    editor.apply();
}`  
For retrieving:
 String getBluetoothName()
{
    String name = "";
    SharedPreferences prefs = getSharedPreferences(Prefer_Bluetooth_name, MODE_PRIVATE);
    name = prefs.getString("name", "No name defined");//"No name defined" is the default value.
    Gson gson = new Gson();
    String json = prefs.getString("MyObject", "");
    mmSocket= gson.fromJson(json, BluetoothSocket);
    return name;
}
But its not Ok.Please help me.
 
     
    