0

I have app with timer task,my app is save the current cell ref and neighbor cell into csv at interval time. My problem is,when i start the app and press 'HOME' screen at device and then i running other app, while i come back to my app via notification, my app is restart again from 0. does anyone know what my problem?

Thank you for any helping...

Kidzie
  • 1
  • 2
  • the os might have killed the app to reclaim memory. so when you come back again its restarted – Raghunandan May 22 '13 at 06:45
  • you need to run your code in separate process – dd619 May 22 '13 at 06:53
  • @Raghunandan : i know because of that, i was looking for answer to not being killed – Kidzie May 22 '13 at 08:58
  • @dd619: i run in separate process – Kidzie May 22 '13 at 08:59
  • @Kidzie i don't think its possible becoz you don't handle the killing part – Raghunandan May 22 '13 at 09:00
  • if you are writing code in in your activity then its not gonna work,you should use service for that and run this service in separate process by setting process attribute of service in manifest – dd619 May 22 '13 at 10:07
  • @dd619 : did you mean, i must startService() in onPause() at activity, and then in service class i running the code? – Kidzie May 22 '13 at 10:25
  • in oncreate() start your service and put your code in this service;and in manifest set its process attribute.after this you will notice that your service keep running regardless of your application – dd619 May 22 '13 at 10:26
  • the user have access for start and stop to save cell, so i must start service when user click on my button start? – Kidzie May 22 '13 at 10:33

1 Answers1

0

Either save ur essential value in the database and retrive it in onStart or onResume OR run ur application as service here

Naveen Prince P
  • 4,521
  • 3
  • 16
  • 17
  • the android is killed in inexact time, so i can't store to database,because while i'm back and the activity recerate again, the condition is not accurately when it stop... – Kidzie May 22 '13 at 08:57
  • @Kidzie commit all transactions to your database in onPause(). – Raghunandan May 22 '13 at 09:01
  • @Raghunandan : i still lost data, for example : if my process is being killed after 1 hour, then the user want to check after 3 hour, so the user missing the data in 2 hour... – Kidzie May 22 '13 at 10:03
  • @Kidzie exactly why you commit data in onpause() cause paused activities are in background and os may kill the same to reclaim memory if it deems it necessary – Raghunandan May 22 '13 at 10:05
  • if i commit in onPause(), when it killed, there's no any block code can be executed. because the app is closed – Kidzie May 22 '13 at 10:27
  • the use a file instead of DB, use Shared preference http://developer.android.com/guide/topics/data/data-storage.html – Naveen Prince P May 30 '13 at 11:16