-7

Hi I have gone though activity lifecyle on many threads, but I could not find what we should do in onStart, onResume, onPause method of the activity.

hamid_c
  • 849
  • 3
  • 11
  • 29
N Sharma
  • 33,489
  • 95
  • 256
  • 444
  • you can check this via Log print. You can write LOG in onStart, onResume, onPause method of the activity and see the Log. – Dileep Patel Sep 27 '16 at 06:24
  • 1
    Possible duplicate of [Difference between onStart() and onResume()](http://stackoverflow.com/questions/4553605/difference-between-onstart-and-onresume) – Amit Vaghela Sep 27 '16 at 06:25
  • 1
    It entirely depends on what your app is supposed to do. THose are hooks you can choose to implement to help your app work, or completely ignore. – Gabe Sechan Sep 27 '16 at 06:25
  • check this : http://stackoverflow.com/questions/8515936/android-activity-life-cycle-what-are-all-these-methods-for – KDeogharkar Sep 27 '16 at 06:26

3 Answers3

2

In the onStart() method, you add code that's relevant at the beginning of the activity.

Let's say, you have an app that reads the temperature of the device's battery. You'll want to have an initial value, so as to show the user. So in the onStart(), you'd add code that goes ahead and fetches the information you'd need, and displays it for the user, before your timer (for example) goes and reads the information a minute later.

The onPause() method is called before the application goes in to the background.

To stay with our example, in the onPause() method, you'd save the last recorded temperature to the device; so you can show a comparison when the user next opens the app.

The onResume() method is called when the application is brought back to the foreground (i.e.: you've gone to the task manager, and tapped on your app to show it again).

Again, staying with the going example; in the onResume() method, you'd go ahead, read your saved data, load fresh data, and show a comparison of the two in the application. Then, when your timer ticks next, only fresh data will be shown.

SimonC
  • 1,547
  • 1
  • 19
  • 43
1

Your question is a bit vague, so answer might not be super specific..

I would say there are no strict "rules" around what we should do in corresponding activity lifecycle methods.

In fact, you can do nothing there (just make sure you call super method if you decided to override those). I.e. your custom activity might not even override these methods - it will work just fine.

onStart, onResume and onPause methods are just hints to you about activity lifecycle change, so you can react accordingly, i.e. start/stop specific to your activity operations at the appropriate time.

For instance, when onResume is called it means that activity became fully visible to the user, so you might want to start some animation (if necessary)

Again, you are not obligated to put any code in there.

Pavel Dudka
  • 20,754
  • 7
  • 70
  • 83
-1

Usually most of the operations are performed within oncreate and onresume. However for your info let me brief it out,

Onstart- this is called after Oncreate, once activity is visible to the user, if you want to perform some operations before the visibility do it in Oncreate, because most of codes should be operated before user views the activity.

OnResume-Be cautious on Onresume is it is quite tricky it will be called whenever you activity is brought to foreground.

Onpause-Called before Onresume, codes wont be executed here, so strictly avoid adding codes in Onpause instead add inside Onresume.

Hope it helps,