Skip to content

Commit

Permalink
android-api: multiple PartnerSession.join() calls not allowed.
Browse files Browse the repository at this point in the history
  • Loading branch information
klauswuestefeld committed Sep 25, 2015
1 parent 1bfe4a1 commit f9c9b64
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class PartnerSession implements Closeable {

private boolean isBound;
private static boolean wasBound;

public static PartnerSession join(Activity activity, Listener listener) {
return new PartnerSession(activity, listener);
Expand All @@ -52,7 +52,7 @@ public interface Listener {

@Override
public void close() {
if (isBound) activity.unbindService(connection);
if (wasBound) activity.unbindService(connection);
}


Expand Down Expand Up @@ -88,14 +88,16 @@ private PartnerSession(Activity activity, Listener listener) {
this.activity = activity;
this.listener = listener;

if (wasBound) finish("PartnerSession has already been joined.");

Intent sneer = activity.getIntent().getParcelableExtra(IPCProtocol.JOIN_SESSION);
if (sneer == null) {
if (SneerInstallation.checkConversationContext(activity))
finish(activity.getLocalClassName() + ": Make sure Sneer session metadata is correctly set in your AndroidManifest.xml file");
return;
}
isBound = activity.bindService(sneer, connection, BIND_AUTO_CREATE | BIND_IMPORTANT);
if (!isBound) finish("Unable to connect to Sneer");
wasBound = activity.bindService(sneer, connection, BIND_AUTO_CREATE | BIND_IMPORTANT);
if (!wasBound) finish("Unable to connect to Sneer");
}


Expand All @@ -105,7 +107,7 @@ private void finish(String endingToast) {
}


public void handleMessageFromSneer(android.os.Message msg) {
void handleMessageFromSneer(android.os.Message msg) {
Bundle data = msg.getData();
data.setClassLoader(getClass().getClassLoader());
Object content = ((Envelope)data.getParcelable(ENVELOPE)).content;
Expand Down

0 comments on commit f9c9b64

Please sign in to comment.