MMKV storage setup in mobile app

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
MMKV storage setup in mobile app
Simple
~1 business day
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1050
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Setting up MMKV Storage in Mobile Application

SharedPreferences on Android and UserDefaults on iOS are synchronous read-write operations for small values, but with non-obvious overhead. SharedPreferences.apply() is asynchronous while commit() blocks the main thread. UserDefaults.synchronize() is deprecated, but usage patterns remain. MMKV from Tencent solves this via mmap: write to memory, OS flushes to disk in background — no explicit flush, no blocking.

Connection

// Android: build.gradle
implementation("com.tencent:mmkv:1.3.5")

// Application.onCreate()
MMKV.initialize(this)
// iOS: Package.swift or CocoaPods
// pod 'MMKV', '~> 1.3'
// or SPM: https://github.com/Tencent/MMKV

import MMKV
// AppDelegate.application(_:didFinishLaunchingWithOptions:)
MMKV.initialize(rootDir: nil)

Initialize once at startup, then MMKV.defaultMMKV() is available everywhere without singletons.

Usage

val kv = MMKV.defaultMMKV()

// Write
kv.encode("userId", userId)
kv.encode("authToken", token)
kv.encode("lastSyncTimestamp", System.currentTimeMillis())
kv.encode("featureFlags", flagsSet)

// Read
val token = kv.decodeString("authToken") ?: ""
val lastSync = kv.decodeLong("lastSyncTimestamp", defaultValue = 0L)

Typed methods for all primitives: encodeInt, encodeBool, encodeFloat, encodeBytes — for serialized Protobuf/JSON objects.

Encryption

MMKV supports file-level AES-128 encryption:

val encryptedKV = MMKV.mmkvWithID("secure-storage", MMKV.SINGLE_PROCESS_MODE, "your-crypto-key")

Never store the encryption key in code — retrieve it from Android Keystore or iOS Secure Enclave:

let key = try KeychainManager.getOrCreateEncryptionKey(identifier: "mmkv-key")
let secureKV = MMKV(mmapID: "secure", cryptKey: key.data)

When MMKV, When Something Else

MMKV is not a database replacement. For key-value pairs with fast access (settings, tokens, small value cache), it's an excellent choice. For structured data with queries, use Room or SQLite.

SharedPreferences to MMKV migration on Android takes an hour — API is nearly identical. Noticeable result: StrictMode warnings about disk read in main thread disappear when SharedPreferences is first read.

MMKV setup with encryption and migration from SharedPreferences/UserDefaults: 1–2 days. Cost calculated individually.