Android: passing a Stack object to another activity results in an ArrayList
<p>I'm trying to pass a <code>java.util.Stack</code> object from an <code>Activity</code> to another in an android app.</p>

<p>The way I do it is to use the fact that the <code>Stack</code> class implements the <code>Serializable</code> interface and pass the object via an <code>Intent</code> object.</p>

<p>The strange thing is that when I use <code>getSerializableExtra(...)</code> in my other <code>Activity</code>, the class of the object has changed from <code>Stack</code> to <code>ArrayList</code>.</p>

<p>I did not find anything about that on the internet.
Do you have any idea of the reason it behaves like that ?</p>

<p>Thanks</p>

<p>Here is a simple code that reproduce the thing (I tried on android 2.3.3 and 4.0.3):</p>

<p>Class A:</p>

<pre><code>package my.test;

import java.util.Stack;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class A extends Activity {

    Stack&lt;Integer&gt; stack;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        stack = new Stack&lt;Integer&gt;();
        stack.push(42);
        stack.push(7);

        Log.i("Class of stack in A (1)",stack.getClass().getName());

        Intent i = new Intent(this,B.class);
        i.putExtra("stack", stack);

        Log.i("Class of stack in A (2)",i.getSerializableExtra("stack").getClass().getName());

        startActivity(i);

    }
}
</code></pre>

<p>Class B:</p>

<pre><code>package my.test;

import java.io.Serializable;
import java.util.Stack;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class B extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Intent i = getIntent();
        Serializable s = i.getSerializableExtra("stack");

        Log.i("class of stack in B",s.getClass().getName());

        Stack&lt;Integer&gt; stack = (Stack&lt;Integer&gt;) s;
    }
}
</code></pre>

<p>Output of <code>Log.i(...)</code>:</p>

<pre><code>04-20 15:36:56.596: I/Class of stack in A (1)(748): java.util.Stack
04-20 15:36:56.596: I/Class of stack in A (2)(748): java.util.Stack
04-20 15:36:56.736: I/class of stack in B(748): java.util.ArrayList
</code></pre>
