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

You must Login before you can answer or comment on any questions.

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.

— asked 8 months ago by Demostenes Garcia
  • Hello,

    Android OS will kill any app in the background if needed. There is no guarantee of multitask or multiple apps running at the same time. If you restart your phone and don't start other stuff, the app will live longer. If you are using a lot of programs, it's likely that your app will be killed.

    In the other hand, what do you mean the "app crashes"? What do you see in the logs?



    — commented 8 months ago by Mauro Parra

  • Hi Mauro,

    I noticed exactly the same. After a fresh start, the app keeps working for a longer period of time.

    However, this is the issue I notice after a while (more likely when using other apps):

    08-28 21:15:08.056: E/TiApplication(2133): java.lang.NullPointerException
    08-28 21:15:08.056: E/TiApplication(2133):  at org.appcelerator.titanium.TiApplication.postAnalyticsEvent(
    08-28 21:15:08.056: E/TiApplication(2133):  at ti.modules.titanium.geolocation.TiLocation.doAnalytics(
    08-28 21:15:08.056: E/TiApplication(2133):  at ti.modules.titanium.geolocation.GeolocationModule.doAnalytics(
    08-28 21:15:08.056: E/TiApplication(2133):  at ti.modules.titanium.geolocation.GeolocationModule.eventListenerAdded(
    08-28 21:15:08.056: E/TiApplication(2133):  at org.appcelerator.kroll.KrollProxy.handleMessage(
    08-28 21:15:08.056: E/TiApplication(2133):  at ti.modules.titanium.geolocation.GeolocationModule.handleMessage(
    08-28 21:15:08.056: E/TiApplication(2133):  at android.os.Handler.dispatchMessage(
    08-28 21:15:08.056: E/TiApplication(2133):  at android.os.Looper.loop(SourceFile:351)
    08-28 21:15:08.056: E/TiApplication(2133):  at
    08-28 21:15:08.056: E/TiApplication(2133):  at java.lang.reflect.Method.invokeNative(Native Method)
    08-28 21:15:08.056: E/TiApplication(2133):  at java.lang.reflect.Method.invoke(
    08-28 21:15:08.056: E/TiApplication(2133):  at$
    08-28 21:15:08.056: E/TiApplication(2133):  at
    08-28 21:15:08.056: E/TiApplication(2133):  at dalvik.system.NativeStart.main(Native Method)
    Does it makes any sense?

    — commented 8 months ago by Demostenes Garcia

  • This is another error after a crash:

    08-29 21:11:21.944: E/TiApplication(18259): (main) [529,790068] Sending event: exception on thread: main msg:java.lang.NullPointerException; Titanium 3.1.2,2013/08/14 12:46,5ceaff8
    08-29 21:11:21.944: E/TiApplication(18259): java.lang.NullPointerException
    08-29 21:11:21.944: E/TiApplication(18259):     at android.view.ViewConfiguration.get(
    08-29 21:11:21.944: E/TiApplication(18259):     at android.view.View.<init>(
    08-29 21:11:21.944: E/TiApplication(18259):     at android.view.ViewGroup.<init>(
    08-29 21:11:21.944: E/TiApplication(18259):     at ti.modules.titanium.ui.widget.TiImageView.<init>(
    08-29 21:11:21.944: E/TiApplication(18259):     at ti.modules.titanium.ui.widget.TiUIImageView.<init>(
    08-29 21:11:21.944: E/TiApplication(18259):     at ti.modules.titanium.ui.ImageViewProxy.createView(
    08-29 21:11:21.944: E/TiApplication(18259):     at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(
    08-29 21:11:21.944: E/TiApplication(18259):     at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(
    08-29 21:11:21.944: E/TiApplication(18259):     at android.os.Handler.dispatchMessage(
    08-29 21:11:21.944: E/TiApplication(18259):     at android.os.Looper.loop(SourceFile:351)
    08-29 21:11:21.944: E/TiApplication(18259):     at
    08-29 21:11:21.944: E/TiApplication(18259):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-29 21:11:21.944: E/TiApplication(18259):     at java.lang.reflect.Method.invoke(
    08-29 21:11:21.944: E/TiApplication(18259):     at$
    08-29 21:11:21.944: E/TiApplication(18259):     at
    08-29 21:11:21.944: E/TiApplication(18259):     at dalvik.system.NativeStart.main(Native Method)
    08-29 21:11:21.960: E/AndroidRuntime(18259): FATAL EXCEPTION: main
    08-29 21:11:21.960: E/AndroidRuntime(18259): java.lang.NullPointerException
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at android.view.ViewConfiguration.get(
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at android.view.View.<init>(
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at android.view.ViewGroup.<init>(
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at ti.modules.titanium.ui.widget.TiImageView.<init>(
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at ti.modules.titanium.ui.widget.TiUIImageView.<init>(
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at ti.modules.titanium.ui.ImageViewProxy.createView(
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at android.os.Handler.dispatchMessage(
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at android.os.Looper.loop(SourceFile:351)
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at java.lang.reflect.Method.invokeNative(Native Method)
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at java.lang.reflect.Method.invoke(
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at$
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at
    08-29 21:11:21.960: E/AndroidRuntime(18259):    at dalvik.system.NativeStart.main(Native Method)
    08-29 21:11:22.088: E/AEE/LIBAEE(198): read_cmdline:com.threetech.tracingapp
    08-29 21:11:22.090: E/AEE/AED(91): jni/../aed/aed_trace.c, 158, No such file or directory
    Any help is more than appreciated.

    Thanks in advance.

    — commented 8 months ago by Demostenes Garcia

1 Answer

Seems like a bug to me.It happens also with Ti SDK 3.2.0. I posted it as

Your Answer

Think you can help? Login to answer this question!