ConditionRacer
ConditionRacer

Reputation: 4498

Android background thread that updates the UI in multiple activities

I'm very new to Android, this is my first app. I'm just looking for someone to point me in the right direction.

I am building an app that will query a server over tcp/ip every minute. I would like to show the status of this server (up/down) at the top of every activity/screen.

My questions are:

1) What should I use to continuously ping a server in the background across multiple activities? For instance, is there a way to spawn a thread from one activity in such a way that it will continue even if the user goes to a different screen?

2) How can I allow this thread to update a status label on whatever screen the user happens to be viewing?

Upvotes: 0

Views: 458

Answers (1)

Volodymyr Lykhonis
Volodymyr Lykhonis

Reputation: 2976

  1. Use services. Please get familiar with documentation first.
  2. You can use service binding or local broadcast messaging to notify your current/front activity about changes from your service

Upvotes: 2

Related Questions