-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathkotlin.txt
264 lines (193 loc) · 9.21 KB
/
kotlin.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
.. meta::
:robots: noindex, nosnippet
:template: product-landing
:hidefeedback: header
:noprevnext:
.. _kotlin-intro:
.. _kotlin-realm-database:
.. _kotlin-realm-database-overview:
.. _kotlin-realm-database-internals:
===========================
Atlas Device SDK for Kotlin
===========================
.. meta::
:description: Use the Atlas Device SDK for Kotlin to store and sync data in Android or iOS apps using the Android platform or Kotlin Multiplatform (KMP).
.. toctree::
:titlesonly:
Realm </sdk/kotlin/realm-database>
Connect to Atlas </sdk/kotlin/app-services>
Manage Users </sdk/kotlin/users>
Sync Device Data </sdk/kotlin/sync>
Logging </sdk/kotlin/logging>
Troubleshooting </sdk/kotlin/troubleshooting>
SDK Telemetry </sdk/kotlin/telemetry>
API Reference <https://www.mongodb.com/docs/realm-sdks/kotlin/latest/>
Release Notes <https://github.com/realm/realm-kotlin/blob/releases/CHANGELOG.md>
Migrate from Java SDK to Kotlin SDK </sdk/kotlin/migrate-from-java-sdk-to-kotlin-sdk>
Use the Atlas Device SDK for Kotlin to develop Android or iOS apps
using the Android platform or Kotlin Multiplatform (KMP).
.. kicker:: Learning Paths
Get Started with the Kotlin SDK
-------------------------------
.. card-group::
:columns: 3
:style: extra-compact
.. card::
:headline: Quick Start
:cta: See Code Examples
:url: https://www.mongodb.com/docs/realm/sdk/kotlin/quick-start/
:icon: atlas_functions
:icon-alt: Functions Icon
Minimal-explanation code examples of how to work with the SDK.
Write to the device database, and sync with other devices.
.. card::
:headline: Working Example App
:cta: Explore an Example App
:url: https://www.mongodb.com/docs/atlas/app-services/template-apps/
:icon: realm_mobile
:icon-alt: Atlas Device SDK Mobile Icon
Learn from example by dissecting a working Kotlin client app that
uses the Kotlin SDK.
.. card::
:headline: Guided Tutorial
:cta: Follow the Tutorial
:url: https://mongodb.com/docs/atlas/app-services/tutorial/kotlin/
:icon: general_content_tutorial
:icon-alt: Tutorial Icon
Follow a guided tutorial to learn how to adapt the example app to
create your own working app.
.. kicker:: What You Can Do
Develop Apps with the SDK
-------------------------
Use the SDK's open-source database - Realm - as an object store on the device.
Use Device Sync to keep data in sync with your MongoDB Atlas cluster and
other clients.
.. tabs::
.. tab:: Store Data with the SDK
:tabid: device-persistence
.. procedure::
.. step:: Install the Kotlin SDK
Choose whether to install the :ref:`Android <kotlin-install-android>`
or the :ref:`Kotlin Multiplatform <kotlin-install-kotlin-multiplatform>`
version of the Kotlin SDK.
Import the SDK in your Gradle files to get started.
.. step:: Define an Object Schema
Use Kotlin to idiomatically `define an object schema
<https://www.mongodb.com/docs/realm/sdk/kotlin/quick-start/#define-your-object-model>`_.
.. step:: Open a Database
The SDK's database - Realm - stores objects in files on your device.
Or you can open an in-memory database which does not create a file.
:ref:`Configure and open a database <kotlin-open-a-realm>`
to get started reading and writing data.
.. step:: Read and Write Data
:ref:`Create <kotlin-create-a-new-object>`, :ref:`read <kotlin-read-objects>`,
:ref:`update <kotlin-modify-an-object>`, and :ref:`delete <kotlin-delete-an-object>`
objects in the database. :ref:`Filter data <kotlin-filter-data>`
using :ref:`Realm Query Language <realm-query-language>`.
.. step:: React to Changes
Live objects mean that your data is always up-to-date.
You can :ref:`register a notification handler <kotlin-react-to-changes>`
to watch for changes and perform some logic, such as updating
your UI.
.. image:: /images/illustrations/2024_branding/Technical_SOFTWARE_Connect(2)_Spot.png
:alt: Atlas Device SDK Mobile Illustration
.. tab:: Sync Data Across Devices
:tabid: device-sync
.. procedure::
.. step:: Connect to an Atlas App Services App
Configure :ref:`Device Sync in an App Services App
<realm-sync-get-started>`. Define data access rules. Use
Development Mode to infer your schema from your data model.
Then, :ref:`connect to the backend <kotlin-connect-to-backend>` from
your client.
.. step:: Authenticate a User
Use one of our authentication providers to :ref:`authenticate a
user <kotlin-authenticate-users>`. App Services provides access
to popular authentication providers, such as Apple, Google, or
Facebook. Use our built-in email/password provider to manage
users without a third-party, or use custom JWT authentication to
integrate with other authentication providers. Anonymous authentication
provides access without requiring a login or persisting user data.
.. step:: Open a Synced Database
:ref:`Configure and open a synced database <kotlin-open-a-synced-realm>`.
:ref:`Subscribe to a query <kotlin-subscriptions>`
to determine what data the synced database can read and write.
.. step:: Read and Write Synced Data
The APIs to read and write data are the same whether you're using
a synced or non-synced database. Data that you read and write to
the device is automatically kept in sync with your Atlas cluster
and other clients. Apps keep working offline and deterministically
sync changes whenever a network connection is available.
.. image:: /images/illustrations/2024_branding/Technical_SOFTWARE_Sync(2)_Spot.png
:alt: Device Sync Illustration
.. tab:: Build with Atlas App Services
:tabid: app-services
.. container::
Call Serverless Functions
~~~~~~~~~~~~~~~~~~~~~~~~~
You can :ref:`call serverless Functions <kotlin-call-function>`
from your client application that run in an App Services backend.
Authenticate Users
~~~~~~~~~~~~~~~~~~
Authenticate users with built-in and third-party :ref:`authentication
providers <kotlin-authenticate-users>`. Use the authenticated user to
access App Services.
.. image:: /images/illustrations/2024_branding/Technical_ACTION_WrenchSettings_Spot.png
:alt: App Services Illustration
.. kicker:: Essential Documentation
Recommended Reading
-------------------
.. card-group::
:columns: 3
:style: extra-compact
.. card::
:headline: Kotlin API Reference
:cta: Kotlin API Reference
:url: https://www.mongodb.com/docs/realm-sdks/kotlin/latest/
:icon: realm_sdk
:icon-alt: Atlas Device SDK Icon
Explore generated reference docs for the SDK's Kotlin APIs.
.. card::
:headline: Migrate from the Java SDK to the Kotlin SDK
:cta: Migrate from Java SDK to Kotlin SDK
:url: https://www.mongodb.com/docs/realm/sdk/kotlin/migrate-from-java-sdk-to-kotlin-sdk/
:icon: general_features_flexibility
:icon-alt: Migrate Icon
Learn why and how to switch from the Java SDK to the Kotlin SDK.
Example Projects
----------------
Explore engineering and expert-provided example projects to learn best
practices and common development patterns using the Kotlin SDK. Check out the
:ref:`<realm-example-projects-table>` page for more Kotlin sample apps.
.. card-group::
:columns: 3
:style: extra-compact
.. card::
:headline: Property-Level Encryption
:cta: Example project
:url: https://github.com/realm/realm-kotlin-samples/blob/main/AppServicesUsageSamples/apps/property-encryption/README.md
:icon: general_security_encryption
:icon-alt: Encryption Icon
Enhance user data security with property-level encryption.
.. card::
:headline: Offline Login and Database Access
:cta: Example project
:url: https://github.com/realm/realm-kotlin-samples/blob/main/AppServicesUsageSamples/apps/property-encryption/README.md
:icon: realm_offline
:icon-alt: Atlas Device SDK Offline Icon
Log in a Device Sync user and open a synced database offline.
.. card::
:headline: User's Online State
:cta: Example project
:url: https://github.com/realm/realm-kotlin-samples/blob/main/AppServicesUsageSamples/apps/presence-detection/README.md
:icon: general_content_users
:icon-alt: Users Icon
Detect connectivity and activity of users and devices.
.. card::
:headline: Connection State Change & Error Handling
:cta: Example project
:url: https://github.com/realm/realm-kotlin-samples/blob/main/AppServicesUsageSamples/apps/error-handling/README.md
:icon: cloud_mobility
:icon-alt: Cloud Mobile Transfer Icon
Learn best practices around handling Sync errors and client reset
strategies.