R
R
raonegaia2019-07-26 16:09:03
Android
raonegaia, 2019-07-26 16:09:03

Android service is recreated when I start calling?

Hello
1) I start Service || JobService via startService || startForegroundService for android Oreo || ContextCompat.startForegroundService
2) in the onCreate method of the service I do startForeground(1, notification), and in onDestroy I do stopForeground(false)
In the onCreate method of the service, BroadcastReceiver is launched, to receive events TelephonyManager.EXTRA_STATE - {OFFHOOK, RINGING, IDLE}
Here is the code for registrations receiver
's applicationContext.registerReceiver(broadcastReceiver, IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED),
Manifest.permission.CALL_PHONE, null)
Immediately after starting the service, I call
val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:+77787020453")
startActivity(intent)
And I start calling
In the service logs I get
18:38:17.008 I/main >>>>: Unstoppable: onCreate ✅
18:38:17.013 4371- 4371/me.myapp I/main >>>>: UnstoppableJob: onStartCommand ✅
18:38:17.231 4371-5110/me.myapp I/main >>>>: Unstoppable - 1 ✅
18:38:18.730 4371-5110/ me.myapp I/main >>>>: Unstoppable - 2 ✅
18:38:19.082 4371-4371/me.myapp I/Unstoppable: blockCallReciever: onRecieve: ✅
18:38:19.082 4371-4371/me.myapp I/ Unstoppable: android.intent.action.PHONE_STATE = OFFHOOK ✅
18:38:21.715 5169-5169/? I/main >>>>: Unstoppable: onCreate ⁉️
18:38:21.741 5169-5169/? I/main>
18:38:21.947 5169-5231/? I/main >>>>: Unstoppable - 1 ⁉️
18:38:24.114 5242-5242/me.myapp I/main >>>>: Unstoppable: onCreate ⁉️
18:38:24.145 5242-5242/me.myapp I/ main >>>>: UnstoppableJob: onStartCommand
⁉️
Unstoppable - 1, Unstoppable - 2 - I started the timer to track whether the service is running or not in real time.
I can’t understand why the service calls onCreate again without calling onDestroy, who can help me solve this and make the service work stably when the call is made?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question