Solved

Get running Intent Service

Posted on 2014-03-27
3
804 Views
Last Modified: 2014-04-02
Hi,

I'm creating an android application that will do a task in a specific time (defined by the user). For this I'm using an Intent Service.

The the problem is if the user closes the application (example: using back button) then I cannot get the the running service to shutdown it, to read information from it (to update my activity when the application opens), etc.

Is this the better approach?

Is there any way to get the running service (intent service)?

Thanks
jpaulino
0
Comment
Question by:jpaulino
  • 2
3 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 39961474
When the user closes your activity the onStop() method of the activity is called (or the onPause(), depending on what made the activity stop). So you could implement your code in one of these two methods.
0
 
LVL 48

Author Comment

by:jpaulino
ID: 39961535
Thanks for the reply.

But the second time the user presses the back button it destroys the activity and the next time it opens, it starts  a new instance.

What I want to achieve is to check if the service is already running. If not, then start a new one, if it's running, then get the state of the timer, selected options, etc, and event shutdown the service (if the user wants it).
0
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
ID: 39961595
You are right, when the user presses the back button your current activity will be destroyed. So when you start your activity again it will be a new instance. You cannot check if your activity is running since there is no activity. I guess what you need to do is to recreate the activity state when the onCreate() method is called (when you start a new activity). You will need to save your activity state in method onSaveInstanceState() and then recreate it by reading the data from the bundle. For more information have a look here.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
runtime exception 2 41
Problem to App source 6 71
hashmap order 17 36
Need Help! Getting a syntax error and don't understand why 3 31
Working settings for French ISP Orange "Prêt à Surfer" SIM cards for data connections only. Can't be found anywhere else !
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question