MBurger Headless CMS
User GuideCMS HeadlessEngagement Platform
  • 🍔MBurger Documentation🍔
  • 🔑 API
    • Introduction
      • Getting Started
      • Structure
    • Common Path
      • Basics
      • POST Bodies
      • POST Relations
      • Evaluating Responses
    • API Authentication
    • Project
    • Blocks
      • Get Blocks
      • Get Block
    • Sections
      • Get Sections
      • Get Section
      • Create Section
      • Update Section
      • Delete Section
    • Media
      • Get All Media
      • Upload Media
      • Get Media
      • Delete Media
    • Integrations / Extensions
      • Authentication Provider
        • Registration
        • Login
        • Logout
        • Get Profile
        • Update Profile
        • Delete Profile
        • Change Password
        • Forgot Password
      • Live Messages
        • Get All Live Messages
        • Send Live Message
        • Delete Live Message
      • In-App Subscriptions
        • InApp Subscription
        • Resume InApp Subscription
      • Shopify
        • Create a Shopify private app
        • Enable Shopify in MBurger
        • Collections Editor
      • Stripe
        • Create Customer
        • Get Cards
        • Create Card
        • Make Default
        • Delete Card
        • Subscription
        • Cancel Subscription
        • Resume Subscription
        • Payment
    • Going Deeper
      • Available Data Types (Elements)
  • 📱 Android SDK
    • Introduction
    • Installation
    • Initialization
    • Fetch for blocks
    • Fetch sections from blocks
    • Mapping to custom objects
    • Admin
      • Delete a Section/Media
      • Create a new Section
      • Update an existing Section
    • Auth
      • Register a new user
      • Authenticate a user
      • User profile
      • Edit profile
      • Other features
    • Proguard Rules
    • Plugins
    • Sample Apps
      • MBurger Explorer
      • MBurger Radio
    • MBurger Apps
  • 🍏 iOS SDK
    • Introduction
    • Installation
    • Initialization
    • Fetch the project
    • Fetch blocks
    • Fetch sections
    • Media
    • Encoding & Decoding
    • Serialization & Equality
    • Admin
      • Add/Edit a section
      • Delete a section
      • Upload media
      • Delete a media
    • Auth
      • Register a user
      • Authenticate a user
      • Retrieve user information
      • Update user profile
    • Plugins
    • Sample Apps
      • MBurger Explorer
      • MBurger Radio
    • MBurger Apps
  • 💻 PHP SDK
    • Installation & Configuration
    • How to use
    • Support & Feedback
    • License
  • ☕ JavaScript SDK
    • Introduction
    • Installation
    • Configuration
    • Methods Reference
    • Support & Feedback
    • License
  • 🔷Flutter SDK
    • Installation
    • Initialization
    • Fetch the project
    • Fetch blocks
    • Fetch sections
    • Media
    • Admin
      • Add/Edit a section
      • Delete a section
      • Upload a media
      • Delete a media
    • Auth
      • Register a user
      • Authenticate a user
      • Retrieve user information
      • Update user profile
  • ❓How to?
    • Basic interactions
      • Blocks
        • Get a Single Block
        • Get multiple Blocks
      • Sections
        • Get a single Section
        • Get Multiple Sections
        • Create a Section
        • Update a Section
        • Delete a Section
    • Advanced section retrieval
      • Filter sections
      • Obtain distance from a section
      • Manage locales and the fallback language
      • Get a section by SLUG
      • Obtain only sections with a defined relation
    • Advanced section creation
      • Create a section with a relation
      • Set the value of a checkbox element
      • Create a section with a multiple or dropdown element
      • Create a section with a SLUG
      • Create a section with SEO
      • Send or schedule a push when creating a section
    • Set the visibility of a section
    • Get images with various format
  • 👻 Sample App
    • Introduction
    • Create an MBurger project
    • Create Home, News and Gallery blocks
    • Create the project
    • Setup the SDK
    • Query the API for items
    • Map your objects from MBurger objects
    • Implement push notifications
    • Take a bite
Powered by GitBook
On this page
  • Listener
  • Actions

Was this helpful?

  1. Android SDK

Fetch for blocks

You should use MBurgerTasks static methods to retrieve data from MBurger dashboard.

This class has public static functions that will call asynchronously MBurger API.

You have 2 ways to retrieve data from API:

  • Listener

  • Actions

Listener

The Listener approach is the easiest one.

With every method of the MBurgerTasks class you should pass the corresponding listener to return data from the function to your control.

All the listeners are inside the MBApiResultsListeners and all of them are simple interfaces that will return the MBurger object you asked for or an error message.

For example, you should use a MBApiProjectResultListener (implementing it to your Activity or Fragment or creating a new one runtime) to obtain Project basic data, so the class will implement these methods:

@Override
fun onProjectApiResult(project: MBProject) {
    /*API call went well*/
}

@Override
fun onProjectApiError(error: String) {
    /*There was an error, you should show it*/
}

Actions

The Action approach is more complicated but more flexible.

It uses LocalBroadcastMessages to send data from the API to your Activity/Fragment using an Action which your Activity/Fragment is listening to.

You can also use this method also if you are doing your own API calls to your server. First you must implement MBGenericApiResultListener which will automatically implement the method.Java

@Override
fun onApiResult(response: MBAPIResponse) {        
}

For example, to obtain the blocks and the project you have to follow these few steps:

  • Create a BroadcastReceiver.

  • Initialize the BroadcastReceiver in your onResume method with the MBurgerApiActionInitializer class specific function.

  • Pause the BroadcastReceiver in your onPause method with the MBurgerApiActionInitializer class specific function.

  • Call the task to send the blocks’ request according to the parameters given in this sample.

  • Fetch the blocks from the response variable of onApiResult.

The code will result:

override fun onResume() {
    super.onResume();
    val actions  = arrayOf(MBAPIConstants.ACTION_GET_BLOCKS, MBAPIConstants.ACTION_GET_PROJECT)
    bRec = MBurgerApiActionInitializer.initializeNookoReceiverCustom(this, this, actions)
    MBurgerTasks.askForProject(this)

    /**Add custom filters to the API call or leave it null**/
    val arrayOfFilters: ArrayList<Any> = null

    /**Inside the blocks returned the “sections” field will be valorized**/
    val getSections = true

    /**Inside the sections the “elements” field will not be valorized (null)**/
    val getElements = false
    MBurgerTasks.askForBlocks(this, arrayOfFilters, getSections, getElements)
    MBurgerTasks.askForProject(this)
}

override fun onPause() {
    super.onPause()
    MBurgerApiActionInitializer.pauseNookoReceiver(this, bRec)
}

override fun onApiResult(MBAPIResponse response) {
/** Check ApiAction to distinguish the responses**/
    if (response.getApiAction().equals(MBAPIConstants.ACTION_GET_BLOCKS)) {
        if (response.getResult()) {
        blocks = (ArrayList<MBBlock>)response.getPayload().get(MBApiPayloadKeys.key_blocks)
        /** Once you received the project’s blocks you can draw your menu**/
        } else {
                Log.e(“ERROR RESPONSE API”, “THERE WAS AN ERROR DURING BLOCKS’ LOADING”)
            }
    }

    if(response.getApiAction().equals(MBAPIConstants.ACTION_GET_PROJECT)){
        if (response.getResult()) {
        project = (MBProject)response.getPayload().get(MBApiPayloadKeys.key_project)
        /** Your code**/
        } else {
                Log.e(“ERROR RESPONSE API”, “THERE WAS AN ERROR DURING BLOCKS’ LOADING”)
            }
    }
}

Note that you can check the ApiAction to distinguish the different responses, and you will find all responses inside the MBAPIConstants class.

In case you previously initialized a BroadcastReceiver only for blocks this check is useless.

This is an example of a single-action BroadcastReceiver initialization (for blocks)

Single action initializationJava

override fun onResume() {
    super.onResume();
    bRec = MBurgerApiActionInitializer.initializeNookoReceiverForBlocks(this, this);
}
PreviousInitializationNextFetch sections from blocks

Last updated 4 years ago

Was this helpful?

📱