Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:58:59+00:00 2026-05-24T00:58:59+00:00

In my app, I store the user’s app data using MySQLite databases, and I

  • 0

In my app, I store the user’s app data using MySQLite databases, and I allow the user to backup the app data to the SD card within a folder that I create on the SD card (let’s call it MyAppFolder). On Android devices that have only a single SD card slot, everything works fine (e.g. my Droid).

However, on devices such as the Galaxy S that have more than 1 SD card, things don’t work. Unfortunately, I don’t actually have one of these devices, so I can’t debug anything, I can only go by user reports. I also did some searching and found this is a known issue. However, I did not find any solutions that didn’t involve just hardcoding the other paths that get used, so I’m looking for some help with that.

In my app, I check and see if MyAppFolder already exists. If not, I create that folder. The folder is always created successfully, although it is created on the “internal” memory slot returned by getExternalStorageDirectory() when there are 2 slots present. However, the files do not get created and copied there. I don’t understand why the folder is created, but the files are not created.

Can someone tell me how I can modify this code to work for devices with 2 card slots as well as 1 card slot? I’d prefer not to hard-code locations to check, but if that’s the only way, I’ll do it just to get things working.

Here is the code I use(slightly modified to make more readable here):

File root = Environment.getExternalStorageDirectory();
String state = Environment.getExternalStorageState();
if( Environment.MEDIA_MOUNTED.equals(state))
{
    File dataDirectory = Environment.getDataDirectory();
    if (root.canWrite())
    {
        String savePath = root + "/MyAppFolder/";
        File directory = new File(savePath);
        if( !directory.exists() )
        {
            directory.mkdirs();  //folder created successfully
        }

        String currentDBPath = "\\data\\my_app\\databases\\database.db";

        File currentDB = new File(datDirectory, currentDBPath);
        File backupDB = new File(savePath, "database.db");

        if (currentDB.exists()) 
        {
            FileChannel src = new FileInputStream(currentDB[i]).getChannel();
            FileChannel dst = new FileOutputStream(backupDB[i]).getChannel();

            dst.transferFrom(src, 0, src.size());

            src.close();
            dst.close();
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:59:00+00:00Added an answer on May 24, 2026 at 12:59 am

    Can someone tell me how I can modify this code to work for devices with 2 card slots as well as 1 card slot?

    “External storage” does not mean “removable storage”. “External storage” means “mountable storage” — IOW, the user has access to that storage when they plug their device into a host machine via a USB cable.

    Android, at present, is designed to allow developers to write things to one external storage point, and it is up to the device manufacturer whether that is fixed flash or something removable. Hence, you should be backing things up to external storage, not thinking that you are backing things up to an SD card.

    Can someone tell me how I can modify this code to work for devices with 2 card slots as well as 1 card slot?

    Use getDatabasePath() to get a database path, rather than the gyrations you are presently going through. Never use concatenation to create paths, the way you are with root + "/MyAppFolder/" — use a File constructor, as you are elsewhere. Make sure you hold the WRITE_EXTERNAL_STORAGE permission. Beyond that, this should work fine for any device with sufficient external storage to hold your database, regardless of how many “card slots” the device may have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've noticed some games in the app store that allow the user to choose
I'm using nhibernate to store some user settings for an app in a SQL
In my app I store some user data in two .plist files which already
I have been designing my app to store local user data which is changed
Originally I was using isolated storage to store user settings in a Silverlight app
I need to store the user's password in my iphone app. When posting an
My current app needs to store address information for a user. I'm currently debating
I know it is a good idea to store configuration data in app.config (e.g.
Example: User installs app v.1.0, adds data. Then the dev submits 10 updates in
I store user-uploaded images in the Google App Engine datastore as db.Blob , as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.