English 中文(简体)
限制穿梭活动之间的物体
原标题:Limitation to passing objects between Android activities

正如其他地方提到的那样;在安乐团活动之间通过事例的方式,是使通过物体能够实施可序列或可包裹的界面。 如我所知,只要你安乐意显示你的狗的年龄和名称,就将处以罚款。 在不使用静态参考的情况下使用更先进的物体是有问题的。

The object to be passed is using e.g. an external library for its purpose. For serializing to work all used classes (incl. in the library) needs to declare this interface, otherwise Android will throw a runtime IOException, stating the object could not be serialized (something is not impl. the serializable interface or has no no-arg constructor). So a library recompilation is required for the serializable approach to work I guess. The Parcel approach requires the object s fields to be written to some output. This output supports custom objects, but then again the passing object (incl. library) needs to implement the serializable interface to work.

利用外部图书馆进行转审有什么解决办法?

问题回答

其中一种做法是,为每个不适于飞行的类型在活动之间穿透Serializer。 这里是一个简单的航天器接口:

public interface Serializer {
    void serialize(Object object, DataOutputStream out);

    Object deserialize(DataInputStream in);
}

之后,您可使用ts或其他任何基地64 encoder/decoder转换。 为此使用的方法如下:

private String serializeToString(Object object, Serializer serializer) {
    ByteArrayOutputStream bStream = new ByteArrayOutputStream();
    DataOutputStream dStream = new DataOutputStream(bStream);

    try {
        serializer.serialize(object, dStream);
    } catch (IOException e) {
        logger.error(e, "Couldn t serialize " + object);
        return null;
    }

    return Base64.encodeToString(bStream.toByteArray(), false);
}

private Object deserializeFromString(String string, Serializer serializer) {
    try {
        return serializer.deserialize(
                new DataInputStream(
                        new ByteArrayInputStream(
                                Base64.decode(string))));
    } catch (IOException e) {
        logger.error(e, "Couldn t deserialize [" + string + "]");
        return null;
    }
}

之后,你可以简单地通过作为<条码>的系列活动通过你的物体,并在需要时将其重新注入你的物体。





相关问题
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 ...