Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

App crashes and saved file of the session are useless

I have an app which runs fine normally however, there are instances where it would crash and the crash seems to damage a file that is created and saved during the run before the crash. The app saves a json file every 5 minutes. I did this so that I can try and save the data to my server. 

 

I cannot identify the cause of the crash itself because it seems to be random and it does not happen to all users so while I'm in this process I'm saving files every 5 minutes as mentioned before. 

 

What baffles is me is why the saved data seems to be empty and I cannot send it to my server anymore.  Is there a possible reason why this happens? 

In addition, is there a way to catch the app before it closes after a crash and save/send data to companion app? 

 

Thanks. in advance

Best Answer
0 Votes
9 REPLIES 9

Could be out of memory, storage space (unlikely), or unresponsive (it needs to return control to the operating system within about 5 seconds).

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thanks @Gondwana for the answer. 
For unresponsive, do yo mean that the app is doing nothing? Because if that is the case then yes there are instances where the app is just waiting for an interaction from the user. Should I just do console logs to avoid this to happen?

Best Answer
0 Votes

I mean the opposite: if your app is doing too much, it will cause a problem. Basically, your app needs to finish what it's doing within five seconds, or the operating system may assume that it's crashed and will kill it. So, whenever you handle an event (timer callback, ontick listener, sensor callback, etc), you can't take any more than five seconds before your app goes idle again.

 

If you're doing extensive manipulation in a loop, or are saving a large file, those could be problems. You can check approximate durations using console.log of the Date either side of potentially slow blocks of code. Don't do this on the sim; it's a lot faster.

 

If you've got code equivalent to this:

while (waitForInput()) {}

...there will be a problem. But you probably haven't done that.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

I see. My apps have several intervals but there is a moment where only one interval is active which is the calculating the step. There is no while loops since the user reactivates another time interval through a button. The thing that I can think of that may cause the app to crash is the saving it self since the json element is accumulating data over time and saving it every 5 minutes may take more time than it should and it crashes the app...

Best Answer
0 Votes

to capture the crash, can I use onunload event? Maybe that can help me atleast save the data correctly since the crash seems to damage the file. 

Best Answer
0 Votes

If you've got so much data in memory that it can't be saved within five seconds, make sure that you're not simply out of memory.

If the save is taking so long that it crashes your app, it won't work any better in onunload. I don't think onunload is called when an app is terminated with extreme prejudice, but I haven't tried it.

Get yourself some telemetry before assuming what the problem is. My guesses could be way off.

Peter McLennan
Gondwana Software
Best Answer

the biggest data saved I have seen is at 10KB. I'll try as you suggested and see where the potential problem is. 
Thank you!! 

Best Answer
0 Votes

I'd be surprised if 10kB is a problem, unless it's being done progressively within a loop. If you can save all the data in a single operation, that will be faster. cbor is your friend, too.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

I think I found the culprit of empty fiile. So here is the thing I have a variable fitbitData but during refactoring at some point it was left as fitBitData. During the saving process I noticed that I was saving fitBitData and not fitbitData. It was not causing a complete error but simply a critical glue error(I think). Is it possible that this error repeated over night may cause the app to crash? 

Best Answer
0 Votes