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

  • Home
  • SEARCH
  • 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 8714603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:38:14+00:00 2026-06-13T05:38:14+00:00

I have a problem implementing what should be a simple example with services. Following

  • 0

I have a problem implementing what should be a simple example with services.
Following the Android developer scheme I managed to Bind to a service. The service works perfectly.

What i want to implement is the starting Date of the Service. I have in the

public class MyService extends Service {

    private Date _firstActivation= new Date();
    ....
    ....
    public Date GetFirstActivation() {
    return _firstActivation;
}
}

In the main activity that binds to the service I have a basic implementation during the OnStart method

 // Check if the Service is running and if it's running let's bind to the service through ServiceConnectionClass
    if (((MyApplication)getApplication())._serviceIsRunning)
    {
        Intent intent = new Intent(this, MyService.class);
        bindService(intent, mConnection, 0);
        _startingTime_TV.setText(_df.format(_myService.GetFirstActivation()));
    }
    else {
        _startingTime_TV.setText("Service Not Started");
    }

where _myService is the MyService and mConnection is the ServiceConnection…

Now what i expect is that once the service has started the first time, each time i Stop the activity (and at the same time unbind) and restart the activity (and at the same time bind) on the textview I can see always the same starting time.

What happens in that the time changes everytime i restart the activity…

Does anyone has a clue?

  • 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-13T05:38:16+00:00Added an answer on June 13, 2026 at 5:38 am

    The lifecycle of the Service is determined:
    – if is started via bindService, the Service is stopped when unbinding
    – if started via startService, it is stopped via stopService or if Android OS wants this

    So first of all: always start your service via startService and then bind to it.
    In your bind you can do: _startingTime_TV.setText(_df.format(_myService.GetFirstActivation()));
    Because after bindService(intent, mConnection, 0); you are not bound yet. You have to wait for a callback: onServiceConnected (function of ServiceConnection)

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

Sidebar

Related Questions

I have a problem with implementing a simple NegaMax in my chess programm. According
I have the following problem, I am implementing a queue abstraction with RavenDB in
We have a strange problem when implementing sessions with ColdFusion in IE6. After login
I have problem developing with live555. I already build the lib-files and example projects
I have the following problem: Suppose I have some basic counter class Counter .
Very simple problem but I'm making no progress so I thought I should ask...
i am currently implementing a simple ray tracer in c++. I have a class
I have a problem with implementing Facebook posting on wall in my iPhone application.
I'm developing simple image sharing site to train my ruby-on-rails-fu. I have following resources
I'm implementing a simple threaded application in which I have a server thread, and

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.