Skip to content
Klaus Wuestefeld edited this page Dec 6, 2017 · 18 revisions

The PartnerSession API lets you create interactive apps such as games and other shared experiences.

In a Chess app, for example, each game of chess will be a session and each chess move will be a message within that session.

Session Type

Add this to an activity section in AndroidManifest.xml:

<meta-data
	android:name="sneer:session-type"
	android:value="chess"/>

That activity will be opened by Sneer when the user starts or opens a chess game session.

API Dependency

Add this to the dependencies section of the build.gradle file in the app folder:

compile 'me.sneer:sneer-android-api:X.Y.Z@aar'

X.Y.Z is the latest version found here. Make sure you are editing the build.gradle file in the app folder. There are others.

Joining the Session

In the activity's onCreate() method, it joins the session to receive the session's messages:

session = PartnerSession.join(this, new PartnerSession.Listener() {
	@Override
	public void onMessage(Message message) {
		//Called for every message sent by you and by your partner.
	}

	@Override
	public void onUpToDate() {
		//Called when there are no more messages pending in the session.
	}
});

PartnerSession.join(...) returns a PartnerSession. In the example above, it is kept in a field.

Sending Messages

session.send(object);

You can send Strings, Integers, Longs, arrays, Maps, and Lists. Do not call send() from an activity's onCreate method or it will freeze.

Handling Messages

message.wasSentByMe() // Returns true if you sent this message, false if your partner sent it.
message.payload() // Returns the value that was sent.

Closing

In the activity's onDestroy() method, it closes the session:

session.close();

The session can still be joined normally by future activities.

Example

The Lizard Spock example app is implemented in a single activity class using the API above.