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 9182567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:35:24+00:00 2026-06-17T18:35:24+00:00

I have this code: DatabaseHandler db = new DatabaseHandler(this); System.out.println(Start – + System.currentTimeMillis()); for

  • 0

I have this code:

DatabaseHandler db = new DatabaseHandler(this);
System.out.println("Start - " + System.currentTimeMillis());
for (int i = 1; i < db.getChampsCount() + 1; i++) {
    String name = db.getChampInfo(i, "name");
    String title = db.getChampInfo(i, "title");
    String thumb = db.getChampInfo(i, "thumb");
    System.out.println("End - " + System.currentTimeMillis());
    [...]
}

and this

String getChampInfo(int id, String col) {
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cursor = db.rawQuery("SELECT " + col + " FROM champions WHERE id = " + id, new String[] {});
    if (cursor != null)
        cursor.moveToFirst();

    db.close();
    return cursor.getString(0);
}

Which is a part of DatabaseHelper class

And it works ok, but the problem is it takes way too long to execute (2089ms on my android phone). Those strings are a part of the UI so I don’t think I can put that in another thread. What can i do to make this code run faster?

Edit: there are exactly 110 rows

  • 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-06-17T18:35:25+00:00Added an answer on June 17, 2026 at 6:35 pm

    Instead of individual statement, should you not use Single sql statement ?

    Just create one ArrayList which will store all the required value in the Activity class.

    e.g: ArrayList<String> myData;

    Now in database helper class make one function like below:

     // TO get All Data of datanase which you want
    public ArrayList<String> getAllData() {          
        ArrayList<String> subTitleList = null;         
        Cursor cursor = null;          
        try {              
        String queryString = "SELECT * FROM champions";              
            cursor =  db.rawQuery(queryString, null);              
            if (cursor != null && cursor.moveToFirst()) {                 
                subTitleList = new ArrayList<String>();                 
                do {                     
                    String nextUser = new String(cursor.getString(cursor.getColumnIndex("name")));                     
                    String nextUser = new String(cursor.getString(cursor.getColumnIndex("title")));                     
                    String nextUser = new String(cursor.getString(cursor.getColumnIndex("thumb")));                     
    
                    subTitleList.add(nextUser);                 
                } 
                while (cursor.moveToNext());   
                System.out.println("it comes in SubTitleList");
            }         
        } 
        catch (Exception e) {             
            e.printStackTrace();             
            subTitleList = null;         
        } 
        finally {             
            if (cursor != null && !cursor.isClosed()) {                 
                cursor.deactivate();                 
                cursor.close();                 
                cursor = null;             
            }             
            if(db != null){                 
                db.close();             
            }         
        }
        //System.out.println("SubTitleList is: "+subTitleList);
        return subTitleList;   
    }
    

    And now in your activity class you can call this function and get all the required data from the myData ArrayList.

    myData = db.getAllData(); // i think there is no need of any ID if you are fetching all the data.
    

    Hope you got my point.

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

Sidebar

Related Questions

I have this code: con.Open(); cmd = new MySqlCommand(String.Format(SELECT concat(name,'|',lastname) FROM {0} WHERE ID=
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
I have this code in XAML <Grid x:Name=LayoutRoot Background=Transparent> <Grid.RowDefinitions> <RowDefinition Height=Auto/> <RowDefinition Height=*/>
I have this code: class LFSeq: # lazy infinite sequence with new elements from
I have this code to count the number of * from a string entered.
i have this code snippet private List<string> FolderOne(string Folder) { string filena; DirectoryInfo dir
I have this code; using System; namespace Rapido { class Constants { public static
I have this code: public void replay() { long previous = DateTime.Now.Ticks; for (int
I have this code to parse url string such as ?var=val but when search
I have this code ListItem item=new ListItem(); item.Text=foo; item.Value=1; ListItem item2=new ListItem(); item2.Text=bar; item2.Value=2;

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.