Just be aware that a "running" service does not necessarily mean it is
currently doing anything...
http://developer.android.com/reference/android/app/ActivityManager.RunningServiceInfo.html#restarting

On Tue, Feb 22, 2011 at 10:27 PM, Apoorva Moghey <
[email protected]> wrote:

> public static boolean isServiceRunning(Context context, String classPath) {
>
>          ActivityManager activityManager =
> (ActivityManager)context.getSystemService(context.ACTIVITY_SERVICE);
>
>         final List<ActivityManager.RunningServiceInfo> services =
> activityManager.getRunningServices(Integer.MAX_VALUE);
>         boolean isServiceFound = false;
>         for (int i = 0; i < services.size(); i++) {
>
>             RunningServiceInfo serviceInfo = services.get(i);
>             ComponentName serviceName = serviceInfo.service;
>
>             if(serviceName.getClassName().equals(classPath)) {
>                 isServiceFound  =true;
>             }
>         }
>         return isServiceFound;
>     }
>
>
> This simple function help me to solve my problem. This function simply
> return boolean value for my service that running or not. Even if my service
> is killed and when next time my application start i know that my service is
> not running .Then my condition become
>
> like this
>
> if ( pendingTask && !isServiceRunning) {
>      //do work
> }
>
>
> On Wed, Feb 23, 2011 at 2:00 AM, Justin Anderson <[email protected]>wrote:
>
>> > "So i m not able get state of service when application start."
>> Right... My take on the original question was that the dev asked how to
>> detect if the service was stopped before the work was done when the main
>> application is launched...
>>
>> My point was that simply moving the location of where the flag is set
>> doesn't always accommodate that...
>>
>>
>> On Tue, Feb 22, 2011 at 1:11 PM, Mark Murphy <[email protected]>wrote:
>>
>>> On Tue, Feb 22, 2011 at 2:19 PM, Justin Anderson <[email protected]>
>>> wrote:
>>> >> Don't wait until onDestroy() to update your flag. Update your flag
>>> >> "when it finishes its work", which by definition will be sooner than
>>> >> -- and hopefully on a different thread than -- onDestroy().
>>> >
>>> > That is a better place to put the flag but that would only work in some
>>> > cases... If the service is killed before the work is done then the same
>>> > problem exists.
>>>
>>> Yes, but then the work isn't done.
>>>
>>> --
>>> Mark Murphy (a Commons Guy)
>>> http://commonsware.com | http://github.com/commonsguy
>>> http://commonsware.com/blog | http://twitter.com/commonsguy
>>>
>>> _The Busy Coder's Guide to Android Development_ Version 3.4 Available!
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to