Android Question The reasons for the crash of the process in the background.

Good day!
I have a program that works in the background, like "MyLocation". During development, I constantly (around the clock) test it for background operation. The background mode worked stably, when suddenly, for a completely inexplicable reason, the internal timer stopped.

It makes no sense to give my code here:
1. The code is too big.
2. Background mode is similar to MyLocation.

The question is rather philosophical: what reasons, in principle, can destroy the background regime?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
If the app crashes then you will see an error message in the logs. It is more likely that the OS killed the process. Many devices don't allow apps to run in the background for too long. Even with a foreground service.

Keep the MyLocation app running and see whether it is killed on your device or not. If not then there is a problem in your app.
 
Upvote 0
If the app crashes then you will see an error message in the logs. It is more likely that the OS killed the process. Many devices don't allow apps to run in the background for too long. Even with a foreground service.

Keep the MyLocation app running and see whether it is killed on your device or not. If not then there is a problem in your app.
Thank you!
 
Upvote 0
If the app crashes then you will see an error message in the logs. It is more likely that the OS killed the process. Many devices don't allow apps to run in the background for too long. Even with a foreground service.

Keep the MyLocation app running and see whether it is killed on your device or not. If not then there is a problem in your app.
It turns out that it is impossible in principle to create a reliable, non-killable application based on MyLocation? What should you do then? How do large firms build such robust applications in general? Or do they have a completely different approach that is not available to the average programmer?
 
Upvote 0
None of the popular apps that you are familiar with, runs in the background all the time.
You haven't given us enough information to actually help you. I can only guess that you should use push notifications.
My program is a Reminder of any events: tomorrow, in a year, ...

The Timer must constantly work in it, a push notification is sent at the right time, plus a voice message about the occurrence of an event and (further) some animation is produced.
Providing code is pointless: the program is already very large. I can assure you that it is based on the MyLocation algorithm.
Apparently, large companies create a database of customers and send them direct mailings in the form of push notifications?
 
Upvote 0
Why do you think that it is related to the company size? Sending push notifications is very simple.

You can also use StartServiceAt to schedule your app to start.
On June 2, 2017, you wrote: "Newer versions of Android makes it more and more difficult to run or start processes in the background." about "StartServiceAt" and "StartServiceAtExact" Delay.

After reading this, I realized that using StartServiceAt and StartServiceAtExact becomes problematic and it is better to abandon them. It is much more reliable, as I understand from your posts, to use the Timer.

Regarding push notifications: sending notifications to clients at the right time means storing clients' personal data and their scheduled reminders on your server. This is not real.
 
Upvote 0

amorosik

Expert
Licensed User
If the app crashes then you will see an error message in the logs.

By 'the logs' do you mean the LOG window of the B4A development environment?
And if the app is loaded in release mode and is running, is there an equivalent of the LOG window of the development environment?
And also, how to know for sure if the app crash was caused by the operating system?
 
Upvote 0
You misunderstood. Timers have nothing to do with background tasks.

StartServiceAtExact will work better than trying to keep the app and device running all the time in the background.
Sorry , I didn't answer right away - I thought for a long time.

The algorithm of my application, in short, is as follows.

The Database stores information: at what time, on what days, in what years, to make a signal - a notification. The timer works with some frequency. When the Timer is triggered, the closest event is analyzed. At the right time, a signal is given: a push notification plus a sound signal plus some animation.

You gave me a very interesting idea.
1. I really need a Timer: I need to make push notifications strictly at a certain time, and StartServiceAtExact works from this point of view, not very accurately. Or am I wrong, and StartServiceAtExact is stable and very accurate?
2. StartServiceAtExact works, as I understand it, much more stable than the Timer. Or can the system also kill StartServiceAtExact from time to time?

Output. It is necessary to combine the efforts of StartServiceAtExact and Timer.
1. In the program, set the StartServiceAtExact to trigger once a day at a certain time, for example, at 00 hours, 00 minutes. Or once an hour, it doesn't matter. When StartServiceAtExact is triggered, we analyze: if the Timer has stopped, we start it again.
2. When the Timer is triggered, we analyze the current time. As soon as the agreed time has come, the same 00 hours, 00 minutes, we give the StartServiceAtExact command to start the timer check service, for example, exactly one day later.

Thus, the Timer and StartServiceAtExact will insure each other against crashes and provide the required accuracy.

Or did I complicate something here and everything is much simpler?
 
Upvote 0
A timer will not help you. It will just stop when the process is killed.

StartServiceAtExact is a good option. Like all background related features in Android, it is not 100% reliable and on some devices the user will need to whitelist your app in the settings.
Questions for the future.
The fact is that after I will make my app under Android, I will do the same for IOS.
Of course, I am aware of the existence of cross-platform views and tools.

I'm interested in?
1. Is there an analogue of the StartServiceTexact for the B4i?
2. How background applications type mylocation are created for iOS.
3. The main thing. What basic principles do I need to stick now if I will translate my application on iOS in the future?
 
Upvote 0
Top