0

I want my app to make a call to server always in background checking for any updates , I am new to android and not sure how to perform this to start with. I just want a single call always running in background. Please guide me with this to start with.

5
  • try IntentService or Service developer.android.com/training/run-background-service/…
    – Napolean
    Apr 22, 2015 at 6:56
  • You can try AsyncTask if you want to check for update once like when starts your app etc. other wise comment of @jenil is good.
    – Waqar Khan
    Apr 22, 2015 at 6:57
  • I want to check updated even if app is not started
    – jenil
    Apr 22, 2015 at 7:00
  • @Napolean Can we keep service always running in background even when app is closed?
    – jenil
    Apr 24, 2015 at 8:07
  • yes you can have it done by using Service class which once started using startService(Intent ) keeps on running indefinitely until unless stopped by using stopService(Intent) or stopSelf() or killed by Android system under memory pressure.
    – Napolean
    Apr 30, 2015 at 6:36

1 Answer 1

0

You can use Async Task for that. In your doInBackground() method, call your service providing some timespan.

Snippet to add timestamp:

Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
    new AddStringTask().execute();
} }, 0, 5000);
13
  • Does this makes a call to server to run for years ? my use case is like has in whatsapp even though we are not online it pops up messages by running in background
    – jenil
    Apr 22, 2015 at 7:02
  • Web services run even for years. In your case, use notifications which are the result of Your service call
    – Hems
    Apr 22, 2015 at 7:04
  • 1
    link this may help you
    – Hems
    Apr 22, 2015 at 7:07
  • pastebin.com/GuzC1ZFk ,i am already calling webservice like this,so u mean to say this already running in background?
    – jenil
    Apr 22, 2015 at 7:08
  • that is eventhough i have come out of my app,this call is made again n again?
    – jenil
    Apr 22, 2015 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.