Indi
Indi

Reputation: 429

How to keep a local database to store data in an android app when the app is offline?

My intention is to develop an android app that has the capability of storing data temporarily to the database even when there is no internet connection and sending those stored data to a remote database when the app has an internet connection. Is there any relevant technology or DBMS or tools to do so? If there is can you please send any references I would go through?

Temporary storing should be able done by many mobile devices into its own store(repository) without the internet connection. When the internet connection is available, the users should have the ability to send those data to a common database(remote).

Upvotes: 2

Views: 9238

Answers (6)

Jakir Hossain
Jakir Hossain

Reputation: 3930

I recommend Firebase Cloud Firestore for most developers starting a new project. Cloud Firestore offers additional functionality, performance, and scalability on an infrastructure designed to support more powerful features.

Cloud Firestore caches data that your app is actively using, so the app can write, read, listen to, and query data even if the device is offline. When the device comes back online, Cloud Firestore synchronizes any local changes back to Cloud Firestore.

For more details Firebase Cloud Firestore

Upvotes: 1

Abhay Paul
Abhay Paul

Reputation: 31

I prefer the ROOM database for storage. The remote syncing functionality can be accomplished using WORK MANAGER API with periodic work requests combined with network constraints.

  1. room: https://developer.android.com/training/data-storage/room

  2. Workmanager: https://developer.android.com/topic/libraries/architecture/workmanager

  3. periodic work: https://developer.android.com/topic/libraries/architecture/workmanager/how-to/recurring-work

Upvotes: 1

Hilary Mwape
Hilary Mwape

Reputation: 455

Don't see much detail but how I would do it is store the data in a Room database:https://codelabs.developers.google.com/codelabs/android-persistence/#0,and then use a method to check for internet connectivity,For instance in Volley this library:https://github.com/adnanbinmustafa/Gloxey-Network-Manager ,has an isNetwork method you can override to check internet connectivity then send that data to remote server using the same library.

Upvotes: 2

bhavya_karia
bhavya_karia

Reputation: 780

You can use the following local databases to store the data and access it in offline mode.

  1. Room Database
  2. Realm
  3. Shared Preferences (Only if the data to be stored is a relatively small collection of key-values)

If you do not want to use any library, then you can use the inbuilt local database,

  1. SQLite

Google provides codelabs on using Room Database for locally storing data

  1. Room Example in Java
  2. Room Example in Kotlin

Upvotes: 2

Antonis Radz
Antonis Radz

Reputation: 3097

I would suggest using internal SQLite database for storing larger data even if it is temporary, there is plenty of Wrapper libraries for that like Room, ORMLite and others...

For smaller datasets like options or preferences use SharedPreferences.

Upvotes: 1

mguest
mguest

Reputation: 131

You can use Room for local offline storage: https://developer.android.com/training/data-storage/room

If you want to have automatic remote sync you can use Firebase Realtime Database: https://firebase.google.com/docs/database

Upvotes: 4

Related Questions