Skip to content

Instantly share code, notes, and snippets.

@dbh4ck
Created January 17, 2018 08:07
Show Gist options
  • Select an option

  • Save dbh4ck/20f1ccba3214da129983c8bbabbb1084 to your computer and use it in GitHub Desktop.

Select an option

Save dbh4ck/20f1ccba3214da129983c8bbabbb1084 to your computer and use it in GitHub Desktop.
Singleton class For Kotlin Android SmackXMPP Connection Sample
package com.db.chatpluskotlin.xmpp
import org.jivesoftware.smack.AbstractXMPPConnection
/**
* Created by DB on 23-12-2017.
*/
public object XMPPLogic {
var connection: AbstractXMPPConnection? = null
var ourInstance: XMPPLogic? = null
@Synchronized
fun getInstance(): XMPPLogic {
var xMPPLogic: XMPPLogic? = null
synchronized(XMPPLogic::class.java) {
if (ourInstance == null) {
ourInstance = XMPPLogic
}
xMPPLogic = ourInstance as XMPPLogic
}
return xMPPLogic!!
}
fun getAConnection(): AbstractXMPPConnection? {
return XMPPLogic.connection
}
fun setAConnection(connection: AbstractXMPPConnection) {
XMPPLogic.connection = connection
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment