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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:49:27+00:00 2026-05-25T22:49:27+00:00

I made an android application that brings information using a web service, then when

  • 0

I made an android application that brings information using a web service, then when the application starts I put the data in a sqlite and I manage everything from my database. After the application starts the data fills a tablelayout.

Now I want to REFRESH that content every 20 seconds (Because information from webservice could changed).

How can I do this? I used the onResume method, but I don’t want to refresh content every time you went back to the tablelayout.

So what I want to do is to execute the oncreate method (which connect with a webservice, fills my tablelayout and display it) every 20 seconds. I read about timer or handler but I’m not sure how can I do this.

Now i have a problem!

i get data from web service and insert data in database in my doInBackground.. thats ok. Now, i create all textviews, the tablerows, etc in the onPostExecute method, but i have 2 problems.
First,

UsuariosSQLiteHelper usdbh =
new UsuariosSQLiteHelper(this, "DBIncidentes", null, 1);

I have a context problem there, in the doInBackground method

and in onPostExecute method, i have the same problem with all the “this” , like TableRow rowTitulo = new TableRow(this);

i know this is a context error, i know basically how context works, but i dont know how to resolve this context problem. i thought that initializing a context in the async constructor may help and i replace in the onpost.. please help!

  • 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-25T22:49:28+00:00Added an answer on May 25, 2026 at 10:49 pm

    First off you do not want to be reading data from a web service OR writing it to a SQLite database in your onCreate method. You need to spawn a new thread for doing this so that it does not cause your application to freeze up. You could create a Thread or use an AsyncTask for this. If you use an AsyncTask, then you can override its onPostExecute method. This will be executed on the main UI thread, so you can refresh your TableLayout in this method.

    Once you’ve got this code working properly, then you just need to schedule it. The easiest way to do this is using a Timer. Here is some skeleton code to help you get started:

    class MyTask extends AsyncTask<Void,Void, MyDataStructure>{
        @Override
        protected MyDataStructure doInBackground(Void... params) {
            MyDataStructure data = new MyDataStructure();
            // get data from web service
            // insert data in database
            return data;
        }
    
        @Override
        protected void onPostExecute(MyDataStructure data) {
            TableLayout table = (TableLayout) findViewById(R.id.out);
            // refresh UI
        }
    }
    
    Timer timer = new Timer();
    TimerTask task = new TimerTask(){
    
        @Override
        public void run() {
            new MyTask().execute();
        }
    
    };
    long whenToStart = 20*1000L; // 20 seconds
    long howOften = 20*1000L; // 20 seconds
    timer.scheduleAtFixedRate(task, whenToStart, howOften);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made an application that is using Android SDK 2.1. This application uses bluetooth
I'm working on an Android application that will send MMS internally without using the
I've developed an android-application that I'dd like to put up on the marketplace. However,
I have made a ListView in my android application. But the problem is that
I have made a web application that administrate questions for a quiz. The web
Last year I made an Android application that scrapped the informations on my train
I made ​​an Android application that uses that uses the SearchManager. The problem is
I have made a Android streaming application that plays media from online URL's. For
I try to use reinstall a application that I made in android. but, istalliation
my android application is formed by several activity, one service (that communicate with a

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.