Short answer to the subject line:
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager)
getSystemService(this.ACTIVITY_SERVICE);
for (RunningServiceInfo service :
manager.getRunningServices(Integer.MAX_VALUE)) {
if
("com.gabriloware.notifier.voicemail.VoiceMailNotifierService".equals(service.service.getClassName()))
{
return true;
}
}
return false;
}
to elaborate a bit, my app will start the service at bootup if it is
configured to do so. The associated activity has a checkbox to allow the
user to control the service and to also indicate the service status.
public class VoiceMailNotifier extends BroadcastReceiver
{
public void onReceive(Context arg0, Intent arg1)
{
SharedPreferences ConfigData =
arg0.getSharedPreferences("user_prefs",
arg0.MODE_PRIVATE);
Boolean StartAtBoot = ConfigData.getBoolean("key_service", true);
if (StartAtBoot) {
Intent startServiceIntent = new Intent(arg0,
VoiceMailNotifierService.class);
arg0.startService(startServiceIntent);
}
}
}
OnPreferenceChangeListener ServiceActiveChange=new
OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object
newValue) {
boolean StartService = (Boolean) newValue;
if (StartService) {
Intent startServiceIntent = new
Intent(VoiceMailNotifierController.this, VoiceMailNotifierService.class);
VoiceMailNotifierController.this.startService(startServiceIntent);
} else {
stopService(new
Intent(VoiceMailNotifierController.this,VoiceMailNotifierService.class));
}
return true;
}
};
On Fri, Jan 31, 2014 at 3:21 PM, dashman <[email protected]> wrote:
> I think your analysis is correct.
>
> I also think it happens because my service doesn't create a worker thread.
>
> In the onStartCommand() method - it sets up some system listeners and
> returns STICKY.
>
> So when the main app is being killed (when i remove it from the active
> apps list) - i think the service
> is being killed - but the onDestroy is not being called (as you mentioned).
>
> I verified with the ps command - and it's gone.
>
> So should I create a worker thread or a handler - i will use it later on
> for some work.
>
>
>
>
>
> On Friday, January 31, 2014 3:01:28 PM UTC-5, Kostya Vasilyev wrote:
>>
>>
>> 2014-01-31 dashman <[email protected]>:
>>
>>
>>> What's confusing is this.
>>>
>>> I've got the app and service running.
>>>
>>> Then using the active app-list option of the launcher, I remove the app.
>>>
>>>
>>> I would think this would kill the app - but not the service.
>>>
>>> Service.onDestroy() is not called.
>>>
>>>
>>> But now if I restart the app - the Service.onCreate() is called
>>>
>>>
>> Sounds like your app's process gets killed. When this happens, the
>> service's onDestroy will not be called.
>>
>> Next when you start the app's UI (activity), the process is created
>> again, and the service is too.
>>
>> You can watch this in the logcat, and for more details, use system
>> settings -> apps -> running, or "adb shell ps", where "ps" is the standard
>> Unix command that gives the list of running processes.
>>
>> -- K
>>
>> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.