Skip to main content

Embedding the Poll in your Mobile App

Navigation is a core part of your app, so our SDK aims to be flexible and allows you to control the navigation.

You will want to consider the following when planning navigation:

  1. Opening the poll after creating it
  2. Navigation to the Details screen of a Poll Option
  3. Opening a poll from a deeplink (for voters)
  4. Closing/Dismissing the poll

PollFragment

The PollFragment handles all of the functionality of viewing and interacting the a poll. The fragment can be used to display the poll after creating it, or for displaying a poll when a user opens it or deep links into it.

In the example below, we are creating an instance of the fragment and presenting it.

    val pollFragment = PollFragment.newInstance(        pollUrl = pollUrl,        flow = OpenPollFlow.createPoll    )    supportFragmentManager.beginTransaction()        .replace(R.id.container, pollFragment, "TAG_POLL")        .commit()

Listener

The PollFragment.PollFragmentListener can be used to receive callbacks about what is happening in the poll.

class MainActivity : AppCompatActivity(), PollFragment.PollFragmentListener {    /// ...    override fun didPressViewDetails(option: PollOptionResponse) {        // TODO: navigate to the details screen for the option    }    override fun didReceiveAnalyticsEvent(event: AnalyticsEvent) {        // TODO: forward analytics to your system (e.g. Google Analytics)    }}

Putting it all together

At this point we have learned how to:

  1. Configure the SDK
  2. Create a poll by mapping our data into the poll fields
  3. Render a poll using the PollViewController
  4. Handle navigating to the Details Screen of an Option

Let's see it all together below

  // configure Polls Platform SDK  val config = Config(      apiKey = "YOUR_API_KEY",      domainConfig = DomainConfig.Subdomain(subdomain = "YOUR_SUBDOMAIN"),      environment = Environment.production  )  PollsPlatform.setConfig(config = config)  // create a poll  val poll = Poll(      ownerId = ownerId,      settings = settings,      title = title,      options = options,  )  val res = PollsPlatform.createPoll(poll = poll)  val pollFragment = PollFragment.newInstance(      pollUrl = pollUrl,      flow = OpenPollFlow.createPoll  )  supportFragmentManager.beginTransaction()      .replace(R.id.container, pollFragment, "TAG_POLL")      .commit()  // deep link into a poll  fun handleDeepLink(uri: URI) {      if (isPollUrl(uri = uri)) {          // this is a poll url        val pollFragment = PollFragment.newInstance(            pollUrl = pollUrl,            flow = OpenPollFlow.openPoll // note we use .openPoll here        )        supportFragmentManager.beginTransaction()            .replace(R.id.container, pollFragment, "TAG_POLL")            .commit()      }  }