Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the best practice if I have multiple activities and fragments #18

Open
starer93 opened this issue Mar 12, 2020 · 1 comment
Open

the best practice if I have multiple activities and fragments #18

starer93 opened this issue Mar 12, 2020 · 1 comment

Comments

@starer93
Copy link

I have a project with multiple activities and fragments. So what is the best way to use Mixpanel? ( I would like to track the whole application)

  • Should I make MixpanelApi singleton?
  • Should I create instances everywhere?

any advice is appreciated.

@RabbiNash
Copy link

RabbiNash commented Dec 9, 2020

Incase anyone needs this. The best advice I would give is that make MIxpanelApi singleton and then access the singleton in all the other classes.

`class MixPanelUtils private constructor(context : Context) {
private val mixPanel: MixpanelAPI = MixpanelAPI.getInstance(context, BuildConfig.MIXPANEL_TOKEN)

companion object {
    @Volatile
    private var instance: MixPanelUtils? = null

    fun getInstance(context: Context) = instance ?: synchronized(this) {
            instance ?: MixPanelUtils(context).also {
                instance = it
            }
        }

    }

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants