Android Question Bug when App is on the background for a random amount of time

German Buchmuller

Member
Licensed User
Longtime User
Hi, I am experiecing a weird behaviour on my Apps. When they are in the foreground they work great, but once they are minimized and therefore sent to background, after some minutes (may be 10 to more than an hour), the app like bugs out. When you open it again (before it was on the background), the Activity_Create event on the Main activity is raised, as if it had been task killed. This causes the app to crash when, for example, the user was in another activity, so when he opens it again, it crashes and says ...view was not initialized.

To sum up, when an app is in the background for a long time, the system partially "kills" it, making it crash when the user opens it again. Any ideas what to do? Thanks!
 

Peter Simpson

Expert
Licensed User
Longtime User
Upvote 0

German Buchmuller

Member
Licensed User
Longtime User
Hi to both of you. Im sure it has nothing to do with starter service and automatic foreground mode. It has to do with memory use. Any app that I make, if I am on an Activity, then minimize the app for a long time and then re open the app, sometimes it starts again from Main activity, and sometimes that Activity that was opened is still open, but when I go back to the previous activity, it starts again. Dont know how to solve this. Any idea? Thanks!
 
Upvote 0

German Buchmuller

Member
Licensed User
Longtime User
Your app should expect activities to be destroyed and recreated. Move all the logic and state that you can to the starter service or to a class that is initialized from the starter service.
I will do that, but many times in the logs it says: Object should be first initialized: (...and a view that was not initialized)
I dont know if it has to do with phone Battery Optimization Permission.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top