-1

I'm learning about android programming from official website(http://developer.android.com). I understand most of life cycle, but I'm not sure when system is destroying activity.

From what I understand, system is destroying activity when some activity stays for longer time in onStop() or when foreground activity needs more resources. Is that right ?

And from what I read the most efficient way to update data base is in onStop(), but let's say user is adding one word to my 'dictionary' application. So I need to gather this words in list and then update data base? Or I should insert rows to DB with each word ( in other method ) ?

ashur
  • 4,177
  • 14
  • 53
  • 85
  • Can you explain a little bit better? You want to know if you should add the word to the DB when the user adds it or just add all the words in onStop()? – takecare Jan 29 '13 at 16:11
  • User fills input field with one word and confirms it. My question: the database should be updated in this moment? Right after confirm or I should gather all words somewhere and wait until onStop() ? I hope it's clear now. – ashur Jan 29 '13 at 16:16
  • It seems to be a very simple, fast DB operation so I think you can add it right away, when the user adds it. Ideally, you would do such thing in a separate thread, however. – takecare Jan 29 '13 at 16:19
  • http://stackoverflow.com/questions/8515936/android-activity-life-cycle-what-are-all-these-methods-for/8516056#8516056 – Yaqub Ahmad Feb 06 '13 at 16:23

2 Answers2

0

As i understand you will never know when android force your application to stop.

So it is like this

onCreate() // here you could initialize

This is safe

onResume() // here turn on

onPause() // here turn off

// After this it is not sure

But if you are sure that finish() is always called you could use others

Mertuarez
  • 901
  • 7
  • 24
0

Data has to be persisted in the onPause()method. Otherwise, the system might terminate your process without further notice.

Dan
  • 1,539
  • 12
  • 23