locked
Run backgrounding code even when the app is killed RRS feed

  • Question

  • User31568 posted

    Hi,

    Some apps like Facbebook and others can still run its backgrounding code even if the app was killed on both iOS and Android

    How can I achieve that please?

    My app is a religions app to remind users about religious times by sending local notification

    That's why i want to make sure it is running even if the app is closed or killed

    Notes: * My code does not run any HTTP, it is just checking the current time and current location * Because the code just check the time, location and then send local notification therefore it does not take log time

    Kindly advise..

    Thanks, Jassim

    Wednesday, October 9, 2019 11:16 AM

All replies

  • User74 posted

    You can queue up your local notifications for specific times and dates when your app is put into background, you don't need to run in background to achieve this.

    EDIT: Apologies, I missed the bit about also requiring location, feel free to ignore my post :smile:

    Wednesday, October 9, 2019 11:54 AM
  • User176749 posted

    you need to use https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers with your local notifications

    Wednesday, October 9, 2019 12:28 PM
  • User31568 posted

    I need to @JohnH because the time might change based on the location

    For example if the user used the app at 11am when he is in Dubai then it has Dubai prayer time

    What if he was at the same time traveling to Bahrain which has a different time and he did not open the app when he arrives Bahrain.. That means his notification will be received as per Dubai time not Bahrain time which is wrong

    For prayer time, I am checking the date, time, latitude and longitude every 30m

    Wednesday, October 9, 2019 12:30 PM
  • User31568 posted

    @batmaci How about PeriodicWorkRequest?

    https://developer.android.com/reference/androidx/work/PeriodicWorkRequest

    Wednesday, October 9, 2019 12:31 PM
  • User379860 posted

    @JassimRahma Do you use WorkManager and PeriodicWorkRequest to excute your task? however, here are several restriction.

    1. The minimum time interval is 15min to execute the task.
    2. Meet the conditions ,then it will perform the task(conditions such as: NetworkType, BatteryNotLow,Charging,StorageNotLow,DeviceIdle)
    3. WorkManager cannot wake up a Activity.
    Wednesday, October 9, 2019 1:13 PM
  • User383174 posted

    Hi You can see my post

    Monday, October 14, 2019 5:26 AM