English 中文(简体)
安德列斯:通过圣克反对另一活动,导致阿雷拉派教徒成为一员
原标题:Android: passing a Stack object to another activity results in an ArrayList
  • 时间:2012-04-20 14:32:53
  •  标签:
  • android

页: 1

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

奇怪的是,当我使用getSerializableExtra(......)时,则物体类别从Stack改为ArrayList

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

Thanks

这里是一部简单的法典,它照搬了这些东西(I在2.3.3和4.0.3英寸上尝试):

A级:

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<Integer> stack;

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

        stack = new Stack<Integer>();
        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);

    }
}

B级:

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<Integer> stack = (Stack<Integer>) s;
    }
}

<代码>记录仪表(......):

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
最佳回答

感谢援助。 看来,它完全触发了这一ug:

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签