Solved

Get running Intent Service

Posted on 2014-03-27
3
775 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX and jaudiotracker playing memory stream 29 66
Java Timer (static) 9 36
xampp tool 12 24
servlet filter example 37 37
Introduction This article is a continuation of Part-1 as evident from the title. Please visit this page (http://www.experts-exchange.com/articles/18706/Backing-up-personal-data-on-your-Android-device-Part-1.html) to read the earlier Part -1. If y…
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.

919 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now