Data Storage

 Data Storage


Android provides several options for storing data such as SharedPreferences, SQLite, and files. SharedPreferences are used to store key-value pairs of primitive data types, SQLite is a relational database management system used for storing and retrieving data, and files are used for storing larger data sets such as images or videos.


Here's an example of how to use SharedPreferences to store and retrieve data:


java


// Storing data in SharedPreferences

SharedPreferences.Editor editor = getSharedPreferences("MyPrefs", MODE_PRIVATE).edit();

editor.putString("name", "John");

editor.putInt("age", 30);

editor.apply();


// Retrieving data from SharedPreferences

SharedPreferences prefs = getSharedPreferences("MyPrefs", MODE_PRIVATE);

String name = prefs.getString("name", "");

int age = prefs.getInt("age", 0);

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...