LocationUpdatesForegroundService app process is still running after closing app - java

I am doing some investigation on Google Play Location Service
Google Play Location Samples
I am experiment the following issue on LocationUpdatesForegroundService sample application: the app process is still running after closing the app.
Steps to reproduce it:
Open app
Press "request location updates" button
Press device home button for sending application in background
Close the app
My expectation is that the app process (and all its threads) has to be stopped but it does not.
The app process is still running after closing the app
It happens when I close the app after calling
startForeground(NOTIFICATION_ID, getNotification());
How can avoid it?
It looks related with the foreground service for collecting location.
How can I stop the service while the app is closing?

As per the documentation the Service is the Android component which run continues in background even if the app is closed.
If you want to stop service when app is remove from recent task(i.e app kill) you have to used android:stopWithTask="true" in AndroidMenifest.xml for explicitly closed the service.
Example ,
<service
android:name=".LocationUpdatesForegroundService"
android:stopWithTask="true" />

Related

Send notification when app is not running

First of all I don't know what type of code to put for my problem.
I'm developing an Android mobile game, with two ways to earn ruby, via mini transactions or via the OfferWall IronSource.
Regarding the OfferWall, those are tasks to complete to then receive Ruby in exchange.
Now my problem that I would very much like to solve
When a user completes a task and the app is not running, how can I send a notification?
zigg, my suggestion would be to call firebase notification while running background service or you can use push notification as Blundell suggested in background service.
The background service will run even if the app is not running. I use foreground services and call push notification in the service when the app is closed or in background.
Hope this helps.

Android services being stopped very soon unless I draw over other apps

My app run from Android 5.0+. I am currently testing my app on a Android 9 device.
I have a service that acts as a client.
I have tried starting the service with both startService and startForeground but it didn't change the outcome (I didn't display any notification in the status bar though). I've noticed that those Services who also draw over other apps won't be killed after few minutes, instead services that only execute background code are being stopped shortly after. Why is that?

How to download a file using WorkManager even when app is killed without having to restart service?

I am trying to download a file by using WorkManager when app is killed, it works completely fine when the app is in the foreground but when the app is killed the service(WorkManager) is restarted and the file starts downloading again.What I want to achieve is something similar to DownloadManagerApi but with custom notification like show progress and resume the download from the point where the app was killed and not restart the service. I have used WorkManager with OneTimeWorkRequest.

Show messages after killing the app

I am currently working on android chatting app using io.socket. When the app opened all the thing is working fine but when I kill the app I am not able show messages.
GCM is a bad idea for messaging because I heard it misses some messages.
service means it will kill the battery.
I want to show messages even if I kill the app(just like watsapp).
Do you have any suggestions, as to, how I can achieve this.
When you kill whatsup app its use Gcm and when you Open your Application its uses XMPP protocol to send and recieve Message. Whatsup app using this both feature in it. so It getting message after killing app too. Whats app app also use MessageService after killing app so It get message regarding.

Will I receive GCM messages if Android kill my app and if I do a Force Close from the settings?

I'm a newbie to Android development and I'm interested in two things which is connected to Google Cloud Messaging.
Does Android absolutely kill applications if they run for a long time in background as iOS does? And if so will I receive GCM notifications after my app was killed by Android?
Is there some difference between Force Close (from the settings menu) and when the app is killed by Android? And if I do Force Close will I receive GCM notifications?
1 - yes, but if you install in your manifest a broadcast receiver that listens for the gcm, it will triggered anyway. What you will do with that event depends on your app. A common practice is to start an intent service that handles the message. It's up to you to make interact with the activities of your app.
2 - From android 3.1, if the user force closes your app, it will stop to be notified of any broadcast until the user does not start your app again. Check "Launch controls on stopped applications" here for more details.

Categories

Resources