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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:28:43+00:00 2026-06-14T19:28:43+00:00

I am creating an application in which I need to always be connected via

  • 0

I am creating an application in which I need to always be connected via a TCP socket. My application already works well in terms of the connection, but when it gets sent to the background, the android system eventually kills the process. This causes it to become disconnected from the server.

I’ve been looking for a way to always keep the application alive, but haven’t found anything.
Could someone tell me what would be the best way to make it so that my application is not closed when it’s in the background, or, barring this, make it restart itself if it is closed?
I’m starting with this and is producing me a headache :S

EDIT
This is part of my code:

  public int onStartCommand(Intent intent, int flags, int startId) {

      Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();

      new Thread(new Runnable() { 
            public void run() {
                Playit();               }
        }).start();


     return START_STICKY;
  }

The app appears to be frozen on startup, though. I do not have a lot of experience, so maybe my mistake is simple and I haven’t noticed it.

  • 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-06-14T19:28:44+00:00Added an answer on June 14, 2026 at 7:28 pm

    Use a Service and start it via startService(). It will run until Android stops it for resources

    Some documentation on services:

    1. http://developer.android.com/reference/android/app/Service.html
    2. http://developer.android.com/guide/components/services.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a moderating application in which i need to fetch all the
I am creating a web application in Java in which I need to run
I am creating a windows phone application, which need to store some data in
I'm creating an application which works on Froyo until Jelly Beans. I have two
I'm creating an application which communicates with the device via FT2232H USB/RS232 converter. For
I'm creating a web application in which teachers need to be able to easily
I am creating an application in which i need to start camera and scan
I am creating an application in which i need to read sdcard images. I
I am creating a application in which I can need to play a video
I am creating a Java application in which I need to read the first

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.