Process life cycle

melamoud

Active Member
Licensed User
Longtime User
hi,

I read the life cycle tutorial for service and activity but I want to clarify something: Is this correct ?

1. when an app get terminated (from task manager for example)
service module get terminated as well - right ?

1.1 in the above case service_distroy and activity_pause will not be called- no way to save state in that scenario right ?

2. if service is called from the OS (registered for an intent) ServiceCreate will be called even if the service was dead before

now to my problem
My app / service is putting a notification on the notification bar, if user kill the app or the phone get into 100% CPU and start to kill processes I have no way to cancel that notification right ?

is there a way to know if a notification exist already, and get the data that presented in it ? (from the service_create Sub) ?

sorry for so many questions in one post:sign0013:
 

melamoud

Active Member
Licensed User
Longtime User
1. Yes.
2. Yes. Service_Create is only called if the service was not running (dead). Service_Start is always called.

There is no way to find the current displayed notifications. However if you use the same ID then there will be no duplicate notifications.


thanks,

the problem is that it will leave a notification and I have no way of clean it up (until the service reboot) - thats too bad
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
it never get called for me, in the following two scenarios
1. I kill it using a task manager
2. it died due to phone issues (activity monitor restart all processes (maybe due to low memeory / CPU dont know)

is it possible I'm doing somethign wrong ?

I put log in it, and never saw it (after many many tests)
I put notification in it and never saw it
I restarted the service after 30 sec (and did not happened as much as I can see)

Nir
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
is it possible I'm doing something wrong ?
I don't think so.

The real question is why do you need to remove the notification when the service is killed? The user doesn't need to know when your service is killed or created.

The user will press on the notification and your process will start if needed.
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
My app put in the notification connectivity infomration
the Wifi SSID + ip or mobile carrier name + IP
and the connected bluetooth device name

when the service get killed the notification might be incorrect so I want to remove it,
in most cases it is ok, since I'm listening to connectivity events and will be awaken when a change happen

so more or less it is ok, but still the edge case is that when the service awake it does not know if a notification exist or not and what it is, so it recreate it (which mean you get an additional vibrate / sound etc for no change what so ever)

I can mitigate it a bit be keeping the state in a file but since it it not 100% that the file got written before the app got killed, I willhave cases where the service started it look at the file decide that the notification is the same (which is not - the change just move to the exact place before the crush) and present wrong status
or decide to do the extra vibrate for not reason

nir
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
thanks, I'm trying not to use it :)
BTW I'm lisenting to events using both Phone lib
and with adding manually to the manifest file ,for example
B4X:
PE.InitializeWithPhoneState("PE", PhoneId) 

AddReceiverText(ConnectivityNotifier, <intent-filter> 
 <action android:name="android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE"/>
 </intent-filter>)

I get duplicate events - but not always,
can you explain the difference between the two (not important the actual action type, assume both are the same)

thanks
 
Upvote 0
Top