I realized an android application which always has to remain activated in the background. To make that, it is enough to use a Service which remains active after the user is left the application.
Nevertheless, if the user rebooting, the application as well as the Service will not be any more active.
How to solve this problem?
I think of having an idea with BroadcastReceiver but I am not on whether it is the best solution.
Thanks in Advance.
So you want the service to restart if the phone is rebooted ?
Create a BroadcastReceiver that listens for BOOT_COMPLETE (you need a permission for this). Have it start your service.
Android may stop your service due to lack of memory.If you have onStartCommand return START_STICKY and have your onCreate of the service call startService on itself, you'll restart when memory is available.
You can set up an alarm to wake your service if its not running, and set up a broadcast receiver on boot which will start the service when the device boot.
Related
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.
I know we can START_STICKY service or use receiver event for start service in android
I'm making chat app for android with java that this service must be active in
any mode in android
There are many method for keep alive this service
START_STICKY
Use phone event
Start Foreground
But I dont know what is best way for keep alive service and android 8 and other version
You know that for chat app,service must be active always for receive new messages
Thanks
I found best solution
We dont have any problem about alive service in android 7 and lower version
Main problem is in android version 8
We can associate service to BroadcastReceiver in manifest and have alive service always
BroadcastReceiver can be TICK or CONNECTIVIYCHANGED or SCREEN event that when this events
occur so us service started without any problem
Thanks
I would like to find out how our Android app can listen when some application is launch (and exit) in an Android device by a user(How to listen to it through Broadcast Receivers or any other way)?
I have searched a lot but not find any satisfactory solution. Please help in this regard. Thanks a lot for your time.
I don't think there's any default way to do that by broadcasts.
You could try using ActivityManager.getRunningAppProcesses
Correction: Listen for the broadcasts android.intent.action.MAIN and android.intent.category.LAUNCHER. Create a broadcast receiver and in the onReceive method check to see the name of the application that is started.
My app will be running in the background and uploads data to the server from time to time. Everything works fine, except that I want my app NOT to upload data to the server on its own by turning on network services. Instead, I want it to only start the upload process when another app or service has started a connection. In some words, I wanna be parasitic to the other app.
I know for a fact that this can be done in Android, however I couldn't find anything in the documentation. Any idea?
I would try registering for the broadcast intent WifiManager.NETWORK_STATE_CHANGED_ACTION, via a BroadcastReceiver. See http://developer.android.com/reference/android/net/wifi/WifiManager.html#NETWORK_STATE_CHANGED_ACTION.
Hope that helps!
I have created (i'm a noob!!!!) a good app that use a service to do some periodic operations.
When the phone is connected to pc via USB (using eclipse with device connected) during test, the service run even in stadby, in the best way possible.
I can see it in logcat and by the result operation...
But when the phone is disconnected the service is running only if the phone is wake up!
How i can solve it without wakelock ?
I mean obtain something like RADIO FM, understand? ;-)
Thanx to all friends!
When the phone is connected to pc via USB (using eclipse with device connected) during test, the service run even in stadby, in the best way possible.
That is probably because the device is not actually in "standby".
How i can solve it without wakelock ?
You can't.
I have created (i'm a noob!!!!) a good app that use a service to do some periodic operations.
Use AlarmManager and something like my WakefulIntentService for this.
I mean obtain something like RADIO FM, understand? ;-)
Android does not have "RADIO FM".