将对象从一个应用程序传递到android中的另一个应用程序 [英] Passing an object from one application to another in android

查看:366
本文介绍了将对象从一个应用程序传递到android中的另一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过大量的糊涂之后,我找不到任何将对象从一个应用程序传递到另一应用程序的方法.尽管我知道我们可以使用Parcel将对象从一个活动传递到另一活动,但是如何在应用程序之间进行操作呢? 我的对象是这个

After lot of googeling, I could not find any way to pass a object from one application to other application.Though I know that we can pass object from one activty to other activity using Parcel but how to do this between applications? My object is this

public class MyObject
{
    private String name;
    public String getName()
    {
        return this.name;
    }
    public void setName(String name)
    {
        this.name=name;
    }
}

然后如何像在活动之间传递对象一样执行此操作

Then how to do this like we do for passing object between activities

intent.putExtra("key",new MyOject());

推荐答案

我假设您同时负责这两个应用程序.

I'm assuming you're in charge of both applications.

其中哪些情况是正确的?

Which of these situations is true?

  • 这两个应用程序都依赖于一个数据存储
  • 这些应用程序是相当独立的,但用户可能希望彼此共享一些数据

如果第一种情况是正确的,通常的方法是创建一个Android Content Provider(如前所述)或一个服务,该服务使用AIDL语言公开API.然后,这两个应用程序都将依赖于内容提供者或服务.

If the first situation is true, the normal way would be to create an Android Content Provider (as suggested previously) or a Service, which exposes an API using the AIDL language. Both applications would then depend upon the Content Provider or the Service.

有关AIDL和服务的信息,请参见此处: http://developer.android.com/reference/android/app/Service.html http://developer.android.com/guide/components/aidl.html

See here for information about AIDL and services: http://developer.android.com/reference/android/app/Service.html http://developer.android.com/guide/components/aidl.html

但是,如果应用程序是对等的,那么有关Intent的现有答案就很好.一个应用程序可以简单地使用startActivity触发另一个应用程序,或者您想为用户提供一种选择从另一个对象共享对象的方法.看这个: http://developer.android.com/training/sharing/send.html

If however the applications are peers, then the existing answers about Intents are good. Either one application can trigger another simply using startActivity, or perhaps you want to provide a way for a user to choose to share the object from one to the other. Look at this: http://developer.android.com/training/sharing/send.html

这篇关于将对象从一个应用程序传递到android中的另一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆