Android Question App is closing after 2 days

Shay

Well-Known Member
Licensed User
Longtime User
(I am opening thread for this issue - subject of other thread is not relevant here)

I have app with service that run in foreground which runs echo player with radio station,
also same app has webview that displaying web site
I have put timer in the service that every 10 minutes refresh the radio + check if web page is still open,
and on the web page I have timer that checks if service is still running and reopen if needed.
after 2 days +- the app is closing it self, without any error / crash / notification.
so both timer I have put is not been able to help here.
Erel you send me some article of app need to be reopen after few days, I have few questions:
1. why is it closing without indication - can I add some debug to understand why it closing?
2. in the article you send it is talking about 2 solutions, SartServiceAt, and watchdog, which one to use? and can you send code example for opening app using other app (watchdog app)
3. If I move service to background will it change something? and why if webview is open the app still closes (the issue I had was with the service closing, but now I have also webview opened and it still close my entire app)
4. Any other idea how to prevent the app from closing? (without additional WD app)

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Some facts:

- The UI cloud devices run the "cloud" app for months.
- Many things happen in the Android OS. You cannot compare it to a Linux server. You should expect your app to quit after some time.

My solution when building the UI cloud was to create a small app that has a foreground service with a wake lock.
This app doesn't do anything except of starting the main app every 30 seconds with StartActivity.

The main app closes itself every several hours automatically.

To answer your questions:
1. Hard to say. Maybe memory leaks. Maybe other things.
2. See my solution above.
3. I don't understand what you mean.
4. No.
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
Erel if I remove the service and put the player inside the webview, do I need to do something in order to keep the app running all the time?
since the issue originally opened about the service been closed, then the app, and the webview is new addon, so I am thinking moving the code from the service to the module and completely remove the service.
do you think it can help? and how do you suggest keeping it running all the time?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
I also have an app that needs to be constantly on to monitor sound in hallways and rooms (children with mental disability).

It has multiple services and one of them is bringing the app to the forground every minute.

On a year the app closes maybe 2 or 3 times from itself or it's not closed but the streams don't work anymore or the phone lags and is unresponsive.

It's software so weird stuff can happen unintended by reasons not always related to your app.

Closing every 2 days seems like something is wrong or not written correctly.

use wakelock, wifilock etc to make sure everything keeps running.

also check for powersaving setting from the OS and additional apps that gets installed on huawei, wiko etc devices to save ever more battery power.

also add your app to the secured apps list or it will kill network connections after a while aswell or not even start your service at boot.
 
Last edited:
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
use wakelock, wifilock etc to make sure everything keeps running.

My app runs 24/7. What @sorex wrote worked in the end for me but I still crash around 8 times a years. (that based off of my app that has been running for 4+ years.) I call that good for Android!
 
Last edited:
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…