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

  • SEARCH
  • Home
  • 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 4584016
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:17:45+00:00 2026-05-21T21:17:45+00:00

How can this be written in its own class to be used over and

  • 0

How can this be written in its own class to be used over and over again? And where the comment line “//Loads the List” is, I need to be able to change that at runtime.

Thnx ahead of time for the info.

/**
 * -- Check to See if the SD Card is Mounted & Loads the Ordered List
 * ======================================================================
 **/
private void storageState() {
    if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_MOUNTED)) {

        orderASC();// Loads the list

    } else if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_UNMOUNTED)) {
        Alerts.sdCardMissing(this);
    }
}

REVISED:

class StorageStateChecker  {
  static void storageState(Activity param, Listener l) {
    if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_MOUNTED)) {

        l.orderASC_Label();//Load the list by Label ASC
        l.orderDSC_Label();
        l.orderASC_Title();//Load the list by Title ASC
        l.orderDSC_Title();

    } else if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_UNMOUNTED)) {

            // Pass context to AlertDialog.Builder
            AlertDialog alertDialog = new AlertDialog.Builder(null).create();
            alertDialog.setTitle("External Storage State");
            alertDialog.setMessage("Your SD-Card is not mounted!  If the device is plugged into a computer via the USB, please disconect the device.");
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    //this.finish();
                }
            });
            // alertDialog.setIcon(R.drawable.icon);
            alertDialog.show();
    }
  }

public interface Listener {
    public void orderASC_Label();
    public void orderDSC_Label();
    public void orderASC_Title();
    public void orderDSC_Title();
  }
}
  • 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-21T21:17:46+00:00Added an answer on May 21, 2026 at 9:17 pm

    I would do this:

    public static boolean performExternalStorageOperation(Runnable doIfMounted) {
        if (android.os.Environment.getExternalStorageState().equals(
                android.os.Environment.MEDIA_MOUNTED)) {
    
            orderASC();// Loads the list
            if(doIfMounted != null) {
                doIfMounted.run();
            }
            return true;
        } else if (android.os.Environment.getExternalStorageState().equals(
                android.os.Environment.MEDIA_UNMOUNTED)) {
            Alerts.sdCardMissing(this);
        }
        return false;
    }
    

    You can replace the Runnable with any kind of generic Listener (I use OnClickListeners a lot for actions that aren’t necessarily clicks) or write your own callback class with a common method to call, but that would be my general approach.

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

Sidebar

Related Questions

I've written this class that returns feed updates, but am thinking it can be
I have written this code to join ArrayList elements: Can it be optimized more?
Ho to do this? What query can be written by using select statement where
In my current project I need to make a certain task create its own
I have 3 models: customer book_manager book The customer can edit its own setting,
Can this MS-Access query be improved? i.e. the SELECT TOP 1 col FROM Table2
Can this be done quickly in jQuery before I start looping through them? Or
Can this be done? It seems like this should be possible. In general, I
Can this be done in JavaScript? type == 1 ? function1() : function2();
Can this be simplified to a one liner? Feel free to completely rewrite it

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.