https://kotlinlang.org logo
#android
Title
# android
a

Akbar

10/15/2019, 7:04 AM
what should I use when I need to work with background in kotlin?
m

Mark McCormick

10/15/2019, 7:46 AM
I believe you are asking about
BroadcastReceiver
a

Akbar

10/15/2019, 8:07 AM
nope ,whenever I get the trigger when the app is in background then I wont be able to open app in foreground right ?
broadcast receiver only sends the triggers or events , but it wont open the app to foregrounf
m

Mark McCormick

10/15/2019, 8:29 AM
You have to start the application in onReceive ofc
m

Matej Drobnič

10/15/2019, 8:29 AM
if you mean background work when app is not open, then use
WorkManager
. If you mean background app when app is open, but you are doing something in the background (for example refreshing some data for the UI to display), then use
coroutines
.
a

Akbar

10/15/2019, 9:15 AM
I mean , I need to open the app after getting notification or trigger from other server when the app is in background
so for this I need to prefer work manager or coroutines?
anyone knows?
m

Matej Drobnič

10/15/2019, 10:02 AM
you use Firebase cloud messaging for that
also this has nothing to do with Kotlin
✔️ 3
a

Akbar

10/15/2019, 10:24 AM
sir I am asking not only about notification , any triggers which I get in background like MQTT server
m

Matej Drobnič

10/15/2019, 11:03 AM
AFAIK you cannot listen to MQTT in the background for more than few minutes since Oreo unless you request battery exclusion (which Google has to explicitly approve to reach Play Store, and good luck with that)
a

Akbar

10/15/2019, 11:16 AM
so how does the calling in whatsapp listen to new calls and open the app ?
m

Matej Drobnič

10/15/2019, 12:09 PM
firebase
y

Yago Lasse

10/15/2019, 12:53 PM
The notification calls an intent to the app, who registers in its android manifest
Whenever you need to click something and open your app, just register in the android manifest a intent filter who knows where to open
p

Pablichjenkov

10/15/2019, 2:10 PM
Those days where we could run Services forever or let our App alive forever are gone. There is only a few alternatives for doing so. 1- Firebase Messaging to send High Priority Messages Notifications that wakes up your App. On Battery Saver it can get dealyed. 2- Foreground Service. Your App runs Forever. Make sure to get Wifi.Awake locks so the radio transceiver don't fall to sleep 3- WorkManager. It has its restrictions. Doze, Standby and Battery Saver applies to it. It smell like the next step is deprecating our beloved Services. The old Trick with continues Alarms awaking the App will be gone soon, I read it the other day in one channel.
a

Akbar

10/16/2019, 5:50 AM
thanks a lot guys
3 Views