Quantcast
Viewing all articles
Browse latest Browse all 8068

Application crashes after a period in the background (including services)

As reference, this is on Android.

I'm noticing this issue with several applications I've done with Appcelerator, all of them: no matter if they are simple apps or complex apps, but is more frequent in larger apps.

For example, I'm working on an application that needs to notify its location (GPS location) every 5 minutes. The application works perfectly when working in foreground, however, every time I put the app on the background (if I minimize the app by using the Home button) the application just crashes and all the services are stopped.

For notifying the application, here's the flow I'm using:

  1. When I start the application, I start an Alarm, using the AlarmManager module.
  2. This AlarmManager, adds a new Alarm Service, which will be triggered every 5 minutes.
  3. Every 5 minutes, the AlarmManager starts the service and notifies the server with the current location.

This works great.

If I hit the "Home" button, the application just crashes (on the Application Manager) sometimes, but is more frequent when using other applications on the foreground while leaving this app on the background.

I thought this was because the main Activity was stopped, so I decided to maintain the main activity / task state by using android:alwaysRetainTaskState="true"

If I reopen the application, the application just restarts. This happens more on low-end devices than on high-end devices, which makes me think that this is a memory issue.

Is this the expected behaviour? If so, how can I mitigate this? Is my current flow the best flow for doing this or is there a better approach?

Any thoughts are more than appreciated.


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>