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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:32:45+00:00 2026-05-15T01:32:45+00:00

I have an Android activity which in turn starts a thread. In the thread

  • 0
  • I have an Android activity which in turn starts a thread.
  • In the thread I open a persistent TCP socket connection.
  • When the socket connects to the server dynamic data is downloaded.
  • The thread sends messages using Handler-class to the activity when data has been received.

Now if the user happens to switch from portrait to landscape mode the activity gets an onDestroy call. At this moment I close the socket and stop the thread.

When Android has switched landscape mode it calls onCreate yet again and I have to do a socket re-connect. Also, all of the data the activity received needs to be downloaded once more because the server does not have the ability to know what has been sent before, i.e. there is no “resume” feature.

Thus the problem is that there is alot of data which is resent all the time when landscape mode is changed.

What are my options here?

  • Should I create a service which handles the socket traffic towards the server thus I always got all the data which the server has sent in the service.
  • Or should I disable landscape mode all together perhaps?
  • Or would my best bet be to rewrite my server which is a VERY BIG job 🙂

All input is welcome 🙂

/ Henrik

  • 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-05-15T01:32:45+00:00Added an answer on May 15, 2026 at 1:32 am

    Either prevent your activity from being restarted (Activity restart on rotation Android) or implement a Service which your application manages. The Service method is very popular with applications I have seen, and allows you some flexibility when tearing down the connection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an activity which have an Update button as menu for android.
I have some problem with Android AsyncTask. There is an Activity which contains some
I have an Android app which includes an activity called Help This uses a
I am new to Android development. I have an activity in which I would
I have a login page (an activity in Android), during which I run an
So I have a very simple android activity that starts a timer when you
I have an android activity in which I'm using tabs. public class UnitActivity extends
I have an Android activity we'll call A which has a button and another
I have a layout for an Android activity in which the second button is
I have an Android activity which has a header, some title text, and then

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.