DataBase & Storage


 

  1. Using OnSaveInstanceState
  2. Shared Preferences
  3. Writing & Reading a File in ExternalStorage
  4. Writing & Reading a File in InternalStorage
  5. File Mangement
  6. Data Backup using BackUpManager
  7. Preference Manager
  8. DataBase
  9. Database to ListView
  10. DataBase to ListView with POJO Class
  11. DataBase to GridView
  12. DataBase to Spinner
  13. DataBase with Image
  14. Reading DataBase from Assets folder
  15. Sharing SharedPreferences Data Between Apps
  16. Sharing InternalStorage Files Between Apps
  17. Sharing Database Data Between Apps

 

1. Using OnSaveInstanceState
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

ScreenShot:

onsave onsave3 onsave4onsave2

Download SourceCode

 

2. Shared Preferences
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

ScreenShot:

shared1 shared2

Download_button

 

3. Writing & Reading a file in ExternalStorage
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

ScreenShot:

file file2 file4file3 file6file5

Download_button

 

4. Writing & Reading a file in InternalStorage
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

ScreenShot:

internal_file4 internal_file3 internal_file2 internal_file

Download SourceCode

 

File Management
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open res -> layout -> Create new xml, display_files.xml and add following code :

Step 4 : Open res -> layout -> Create new xml, list_items.xml and add following code :

Step 5 : Open src -> package -> MainActivity.java and add following code :

Step 6 : Open src -> package -> Create new class, DisplayFiles.java and add following code :

Step 7 : Open AndroidManifest.xml and add following code :

ScreenShot:

file_management file_management1 file_management2 file_management3 file_management4 file_management5 file_management6 file_management7

Download SourceCode

 

6. Data BackUp using BackupManager

!!Note: In order to make a data backup application, you need to register your application with google backup service. Click here to register. Just provide your package name and accept licence, you’ll get the key.

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyBackupAgent.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:

backup backup2

Download_button

 

7. Preference Manager
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> Create new xml folder and create new xml file, user_setting.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :