开发者

Sharing data between two android applications

I have a java application that stores some GPS data in a strange format:

(latitude,longitude,workerId) using this class:

public class Coordinate {
  private final double lon;
  private final double lat;
  private final int workerId;

  public Coordinate(double lat, double lon, int workerId) {

    this.lat = lat;
    this.lon = lon;

    this.workerId=workerId;
  }

  public double getLon() {
    return lon;
  }

  public double getLat() {
    return lat;
  }
  public int getwId(){
      return workerId;
   }
}

The thing is that each time I have a (longitude, latitude) I must add a workerId (which is an int) to that pair.

Now here is my problem:

The data in this format I'm sending it to an android application which is not familiar with this format....

Do u know by any chance if there is any possibility how could I get my longitude and latitude back from this format on the android side of my whole app?

I have my reasons for sending the data under this form:)

If I built in my android app a class just like this one used to wrap the data....I could get y raw data back?

Update:

My first app is in java and is a server that listens for incoming connections to a specific p开发者_Go百科ort.

My second app is on android and is a sort of client.

These two communicate through a socket....SO no disk writing....no nothing. The first one is on a local machine and the second on a mobile phone.

And yes,I'm sending through socket and instance of the class from above!

Something like:

Coordinate coord=new Coordinate(lat,long,id);    
os.println(coord);

How do I get my data back on the android app?


I guess your Application is sending an instance of the class you showed? If so, why don't you give your Android App the class-file so you can recreate the Object and read from it?

If you want to share things between two Android-Applications on the same device, a ContentProvider is used.


You can't just send an Instance of an Object and receive it on the other side. The Object must be serialized and unserialized (on the receivers side). Therefore, Java has the ObjectOutputStream- and the ObjectInputStream-classes.


If you're sending the data to another app are you using an Intent to launch it? If you are you can have a storage class that implements serializable and pass the data in the Bundle with the Intent. If you are not launching with an Intent you can write the data out to disk and read it in from the other app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜