user2082987
user2082987

Reputation: 1731

keep an activity running in background

I am sending some data from my activity to a server. I keep it running in background using:

public void onBackPressed() {
    moveTaskToBack (true);
}

But if the data is not being send for say about 10min because of some network problem. After recovering from n/w problem it doesnt continue to send.

Why is it so? Does the activity stops after sometime if it has nothing to do?

Upvotes: 0

Views: 1586

Answers (2)

Cyph3rCod3r
Cyph3rCod3r

Reputation: 2086

You can simply start a Service that will run in background and send your data to server. If you call that in main thread of the activity it may hang you activity and could not process it because activity has a life cycle. It may end UP! start a background service and perform all the operation in it. :)

Upvotes: 2

npace
npace

Reputation: 4258

Check out the documentation. This method just moves your activity to the back of the activity stack, it is still being paused, and so - eligible for finalization by the OS. Your activity is probably being destroyed.

If you want a certain process to keep running while your activity is paused, either use a service, like Raghunandan suggested, or start an AsyncTask if you need to update the UI after your data sending has completed.

Upvotes: 1

Related Questions