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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:21:39+00:00 2026-06-13T13:21:39+00:00

This is my service class in that i increment the i value based on

  • 0

This is my service class in that i increment the i value based on time…

    public class BackService extends Service {
    int i=0;
    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }
    @Override
    public void onCreate() {
        pollForUpdates();
        super.onCreate();
    }
    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
    }
    private void pollForUpdates() {
        Timer timer=new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                    Log.v("Service class called", "service class called "+i);
                    getRunningApps();
                    i++;
            }
        },0,1000);
    }
    private void getRunningApps()
    {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}

I want to append the i value to the TextView. i.e the TextView value is dynamically change based on i value…

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    startService(new Intent(this, BackService.class));
    TextView tx=(TextView)findViewById(R.id.textView1);

}}

how to append the i value to tx…

Thank you in advance..

  • 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-13T13:21:40+00:00Added an answer on June 13, 2026 at 1:21 pm

    Use this

    public class MainActivity extends Activity {
         TextView tx;
         RefreshBroadcastReciver mBroadCastReciver;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        startService(new Intent(this, BackService.class));
        tx =(TextView)findViewById(R.id.textView1);
    
    }
    @Override
    protected void onResume() {
        super.onResume();
        mBroadCastReciver = new RefreshBroadcastReciver();
        registerReceiver(mBroadCastReciver, new IntentFilter("sendData"));
    }
    private class RefreshBroadcastReciver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            tx.setText(intent.getIntExtra("i", 0)+"");
    
    }
    }
    @Override
    protected void onStop() {
        super.onStop();
        if(mBroadCastReciver!=null)
        unregisterReceiver(mBroadCastReciver);
    }
    }
    

    and your service is here

    public class BackService extends Service {
    int i=0;
    Intent intent1;
    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }
    @Override
    public void onCreate() {
        pollForUpdates();
        super.onCreate();
    }
    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
         intent1=new Intent("sendData");
    }
    private void pollForUpdates() {
        Timer timer=new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                    Log.v("Service class called", "service class called "+i);
                    getRunningApps();
    
                    i++;
                    Message msg=new Message();
                    msg.arg1=i;
                    handler.sendMessage(msg);
            }
        },0,1000);
    }
    private void getRunningApps()
    {
    
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
    protected Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            intent1.putExtra("i", msg.arg1);
            sendBroadcast(intent1);
        }
    };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that describes a service: public class navigation_web extends Service {
I've created a class that extends Application. This class starts a service when the
I currently have service classes that look something like this public class UserService :
I have two entities like this: public class Service { public virtual int ServiceId
I'm binding to Service by this way: Activity class: ListenLocationService mService; @Override public void
So I have this service class that utilize Restkit to consume REST web services.
I have a Windows service built upon ATL 7's CAtlServiceModuleT class. This service serves
Typically you start a service like this Intent i = new Intent(context,MessageService.class); context.startService(i); but
This is my query: class services extends Zend_Db_Table{ function Get_Services($user_id){ $DB = Zend_Db_Table_Abstract::getDefaultAdapter(); $select
I have a Jersey REST service with a resource class that calls methods on

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.