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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:49:01+00:00 2026-05-31T00:49:01+00:00

I have used SimpleCursorAdapter for display the data into a list in my activity

  • 0

I have used SimpleCursorAdapter for display the data into a list in my activity class.I am getting the data from Sqlite DB and applying to listview.I am inserting the data from service class.In my service class i am getting the data from WEB services and inserting latest into Sqlite mobile database this service class will run on every 5 sec’s for check the latest at Web service then bring it and insert into Sqlite db.when ever the new record is inserted into Sqlite db the listview is not updating with latest inserted record.I have implemented my application as follows:

MyActivity.java

private MySqliteHelper msh;
ListView lst;
Cursor cursor;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        msh = new MySqliteHelper(MyActivity.this);
        msh.openToWrite();
        lst = ((ListView)findViewById(R.id.listView1));
        cursor = msh.queueAll();

        String getFromDB[] = new String[]{MySqliteHelper.KEY_CONTENT1,MySqliteHelper.KEY_CONTENT2};
        int toView[] = new int[]{R.id.msgId,R.id.usrmsg};

        lst.setAdapter(new SimpleCursorAdapter(this, R.layout.list, cursor, getFromDB, toView));

       //calling service class
        bindService(new Intent(ShoutGetMessagesActivity.this, ShoutRepeatService.class), mConnection, Context.BIND_AUTO_CREATE);

        updateList();
    }

      private void updateList(){
              cursor.requery();
               }


        RepeatService bg;
        private ServiceConnection mConnection = new ServiceConnection() {

            public void onServiceConnected(ComponentName className, IBinder binder) {

                bg = ((RepeatService.MyBinder) binder).getService();

                Toast.makeText(MyActivity.this, "Connected",
                        Toast.LENGTH_SHORT).show();

            }

            public void onServiceDisconnected(ComponentName className) {
                bg = null;
            }
        };
    }

RepeatService.java

    ArrayList<NewMessages> result;
    private MySqliteHelper msh;

     private Timer timer = new Timer();
     private static final long UPDATE_INTERVAL = 500;



    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onCreate() {
          msh = new MySqliteHelper(this);
            msh.openToWrite();

       pollForUpdates();

     super.onCreate();
    }

        private void pollForUpdates() {
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                Log.v("Last message ID", "====>"+MySqliteHelper.LastMsgID);

                if(MySqliteHelper.LastMsgID==null){

                    MySqliteHelper.LastMsgID="0";

                }

                result = new ParseXml().convertUsersDetails(new Generic().getLatestFromWebService(MySqliteHelper.LastMsgID));


                 for(int i=0;i<result.size();i++){
                    String msgs =result.get(i).getMessages();
                    String msgID = result.get(i).getMsgId();
                        Log.v("messages", "------------>>>>"+msgs);
                        Log.v("messageIDs", "--------->>>>>>"+msgID);
                        msh.insert(msgID, msgs);
                    }   

            }
        }, 0, UPDATE_INTERVAL);

        Log.v(getClass().getSimpleName(), "Timer started.");

    }



         private void updateList(){
      cursor.requery();
       }

    public class MyBinder extends Binder {
        RepeatService getService() 
        {
            return RepeatService.this;
        }
    }
}

From the above service class i am getting latest records and inserting to Sqlite db.
How can i update from this service class to View class?

please any body help me

  • 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-31T00:49:03+00:00Added an answer on May 31, 2026 at 12:49 am

    You can create a broadcast using intent to call a function in the activity from the run() method of service

    private void pollForUpdates() {
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            Log.v("Last message ID", "====>"+MySqliteHelper.LastMsgID);
    
            if(MySqliteHelper.LastMsgID==null){
    
                MySqliteHelper.LastMsgID="0";
    
            }
    
            result = new ParseXml().convertUsersDetails(new Generic().getLatestFromWebService(MySqliteHelper.LastMsgID));
    
    
             for(int i=0;i<result.size();i++){
                String msgs =result.get(i).getMessages();
                String msgID = result.get(i).getMsgId();
                    Log.v("messages", "------------>>>>"+msgs);
                    Log.v("messageIDs", "--------->>>>>>"+msgID);
                    msh.insert(msgID, msgs);
                }   
    
        }
    *************************************
    Intent intent = new Intent();
    intent.setAction("com.example.updatelist");
    sendBroadcast(intent); // finally broadcast
    *************************************
    
    }, 0, UPDATE_INTERVAL);
    
    Log.v(getClass().getSimpleName(), "Timer started.");
    
    }
    

    And in your activity you have to receive the broadcast intent and update the list

     // Register Broadcast Receiver to receive broadcast intent in oncreate method
    
    public oncreate()
    {       
    IntentFilter filter = new IntentFilter("com.example.updatelist");
            registerReceiver(myReceiver, filter);
    }
    
    private BroadcastReceiver myReceiver = new BroadcastReceiver() {
    
        @Override
        public void onReceive(Context context, Intent intent) {
    
        msh = new MySqliteHelper(MyActivity.this);
        msh.openToWrite();
        lst = ((ListView)findViewById(R.id.listView1));
        cursor = msh.queueAll();
    
        String getFromDB[] = new String[] MySqliteHelper.KEY_CONTENT1,MySqliteHelper.KEY_CONTENT2};
        int toView[] = new int[]{R.id.msgId,R.id.usrmsg};
    
        lst.setAdapter(new SimpleCursorAdapter(this, R.layout.list, cursor, getFromDB, toView));
    
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SimpleCursorAdapter for my ListView, the view is set from NewView. I'm
I have successfully used a SimpleCursorAdapter to list displayname and value (both in my
I have implemented an application to get the data from local mobile SQLite db
I have a main activity that takes elements from a database and displays them
I have used several looking glass tools from servers around the world. What I'm
I have used a custom class to implement shared resource functionality in my WPF
I have used the smtp class to send emails through code. Can I use
We have used Custom List View inside that one Text View and two Edit
I have used to following code to display the favorite item listing. It has
I have a database with one row of data that will be used across

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.