0

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?

1

2 Answers 2

2

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. :)

1

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.

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.