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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:23:56+00:00 2026-05-27T05:23:56+00:00

I am trying to insert some data into the database if the app is

  • 0

I am trying to insert some data into the database if the app is running for its first time, so I create a progressbar and a thread to do that ,but the thread seems not running and the progressbar just keep showing, can anyone explain why, thx

my code:

public class HDtvs extends Activity implements Runnable {
    /** Called when the activity is first created. */

    private Button likebutton;
    private ImageButton about;
    private ChannelDB mDB;
    private ListView channellist;
    private Cursor c;
    private ProgressDialog d;
    private String channelS_TABLE;

    @Override    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        likebutton=(Button) findViewById(R.id.share);
        about =(ImageButton)findViewById(R.id.about);
        channellist = (ListView) findViewById(R.id.Channel);

        if (tabIsExist(channelS_TABLE) != true){
        d=new ProgressDialog(HDtvs.this);
        d.setMessage("由于您第一次使用,本程序正在创建数据库,请稍后···");
        d.show();
        /* 启动另一个Thread,运行run() */
        Thread thread = new Thread(HDtvs.this);
        thread.start();
        }else{
            filldata();
            Log.d(this.toString(),"database exist");
        }

    }


    public void filldata(){
        mDB = new ChannelDB(this);

        String[] columns = {mDB.KEY_ID, mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_PATH, mDB.KEY_DBLINK};
        String   table   = mDB.channelS_TABLE;

        c = mDB.getHandle().query(table, columns, null, null, null, null, null);

        startManagingCursor(c);

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                R.layout.channelview,
                c,
                new String[] {mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_DBLINK},
                new int[] {R.id.poster, R.id.channel, R.id.douban});

        adapter.setViewBinder(new ChannelViewBinder());

        channellist.setAdapter(adapter);

        channellist.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                c.moveToPosition(position);
                Intent intent = new Intent();
                intent.setClass(HDtvs.this,Showlist.class);
                Bundle bunde = new Bundle();
                bunde.putString("path",mDB.KEY_PATH);
                bunde.putString("cname",mDB.KEY_CHANNEL);
                bunde.putString("dblink",mDB.KEY_DBLINK);
                /* 将Bundle对象assign给Intent */
                intent.putExtras(bunde);

                startActivity(intent);
            }
        }); 
    }
    private Handler handler = new Handler()
    {
      @Override 
      public void handleMessage(Message msg)
      { 
        d.dismiss();

      }
    };

    @Override
    public void run()
    {
      try
      {
          mDB.Reset();

          insert some data

          handler.sendEmptyMessage(0);          
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
    }

 } 
  • 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-27T05:23:56+00:00Added an answer on May 27, 2026 at 5:23 am

    it is easier to use the AsyncTask for that:
    Create a new inner class which extends from AsyncTask:

      private class MyTask extends AsyncTask<String, String, String> {...
    

    In the AsyncTask-Method doInBackground you can put your Database code.

    Simply start the AsyncTask with new MyTask().execute(); from e.g. onCreate.
    If you want to have a ProgressBar you need to take a look at the onPreExecute, onPostExecute and onProgressUpdate Methods.

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

Sidebar

Related Questions

I have a form that is trying to insert some data into an SQL
I'm trying to insert some data from a proprietary JSON database into MongoDB for
I am trying to INSERT some data into a database. I can do this
I'm trying to seed some data into a Rails 3 app that I'm developing,
I ma trying to insert some data into the database. The data contains single
I'm trying to insert some data into a database using an html form. The
I'm trying to insert some data into my mysql database. The connection is working
I'm trying to insert some data into a local MySQL database by using MySQL
I am trying to insert some text data into a table in SQL Server
I'm trying to insert some new objects into a firebird database using NHibernate. I

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.