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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:13:00+00:00 2026-05-18T03:13:00+00:00

I am having a weird situation where a Service that is created is stopping

  • 0

I am having a weird situation where a Service that is created is stopping – sometimes. I have a entry Activity A that starts a service using bindService

// if we now have an IP address then bind ourselves to the MessageService
bindService(new Intent(this, MessagingService.class), 
            onMessageService,
            BIND_AUTO_CREATE);

The MessageService handles kicking of Read and Send threads to handle message traffic with the app. It basically handles polling for new messages at 1 second intervals using a StatusTask and it’s timer using timer.scheduleAtFixedRate.

Activity A then kicks off another Activity B that displays info to the user. For some reason that I yet to figure out, most of the time when I press the home button, the polling stops and the Service seems to have stopped. Reslecting my app from the Home recent apps list or via a notification I post when not visible brings the Activity to the foreground, but the Service seems to be gone. Making this harder to debug, about 10-20% of the time everything works great and the Message Polling service keeps plugging away.

Should I be using startService instead? The only direct relationship that the second Activity B has with the Service is that registers itself as an observer of the Read thread in order to be notified about timeouts on Reads. I am not calling stopService anywhere in my code.

  • 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-18T03:13:00+00:00Added an answer on May 18, 2026 at 3:13 am

    public class Testservice extends Service {

    private static final String TAG = Testservice.class.getSimpleName();

    public Timer timer;
    TimerTask scanTask;
    final Handler handler = new Handler();
    Timer t = new Timer();

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    
    }
    
    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "Service creating");
        _startService();
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "Service destroying");
    
        t.cancel();
        t = null;
    }
    

    public void yourfunction()
    {

    }

    //this will invoke the function on everysecond basis so try it if it helpsa
    public void _startService(){

        scanTask = new TimerTask() { 
                public void run() { 
    
                        handler.post(new Runnable() { 
                                public void run() { 
    
                                    yourfunction();
    
                                } 
                       }); 
                }}; 
    
                t.schedule(scanTask, 1000L, 1000L);  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a very weird situation that is driving me nuts. I have a
I'm having a bit of a weird situation here. I have a form that
I have a weird situation. A client of mine has a website having this
Having a weird issue. I'm new to Macs and have a windows VM that
I'm having a weird situation that I'm trying to understand. This piece of code
Im having a weird issue here; The following .htaccess works but now (after changing
I am having a weird issue with nuget.exe command line tool. I have a
i'm having a weird problem about copying with Xcopy. I'm using Windows Server 2008
I'm having really weird situation. I create a singletone object of a class named
I am having a weird Situation with my DataConext. All My code is in

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.