Understanding activity lifecycle
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am just starting my experience with Android development (I am watching tutorials right now). I looked at the activity lifecycle on the Android developers page, and I realized that the activity always goes through the onResume()
method before it's visible to the user. Assuming I will be using no fragments in the activity, does that mean that most of the code logic should be within the onResume()
method, and I should just inflate the layout once inside the onCreate()
at the beginning?
android android-activity activity-lifecycle
add a comment |
I am just starting my experience with Android development (I am watching tutorials right now). I looked at the activity lifecycle on the Android developers page, and I realized that the activity always goes through the onResume()
method before it's visible to the user. Assuming I will be using no fragments in the activity, does that mean that most of the code logic should be within the onResume()
method, and I should just inflate the layout once inside the onCreate()
at the beginning?
android android-activity activity-lifecycle
1
It really depends on what you expect from the activity. Do you have work that needs to be done everytime the activity is shown? Or just once at the creation of the activity?
– Luca Nicoletti
Nov 14 '18 at 9:07
3
one-time initialization goes in onCreate, some times initialization of stuff can go in onResume depending on what you need as Luca said. Most of the code is usually in event listeners such as onClick for the UI click events. onResume is usually reserved for registering listeners and callbacks, unless you're doing something special. There will be many cases where you have an activity that does not override onResume simply because there is no need
– Tim Castelijns
Nov 14 '18 at 9:08
1
initialization of resources and variables should be done in onCreate(). because, when the Activity goes into onPause() or onStop() the onResume() will be call and the same variables and resource will be initialized and memory will be wasted. If your logic to run every time when the activity goes into background and come back to foreground, based on priority write the logic in onStart() and onResume().
– Chethan Kumar
Nov 14 '18 at 9:15
Thanks guys I understood it better now. Just a beginner's misunderstanding
– user9644796
Nov 14 '18 at 9:23
add a comment |
I am just starting my experience with Android development (I am watching tutorials right now). I looked at the activity lifecycle on the Android developers page, and I realized that the activity always goes through the onResume()
method before it's visible to the user. Assuming I will be using no fragments in the activity, does that mean that most of the code logic should be within the onResume()
method, and I should just inflate the layout once inside the onCreate()
at the beginning?
android android-activity activity-lifecycle
I am just starting my experience with Android development (I am watching tutorials right now). I looked at the activity lifecycle on the Android developers page, and I realized that the activity always goes through the onResume()
method before it's visible to the user. Assuming I will be using no fragments in the activity, does that mean that most of the code logic should be within the onResume()
method, and I should just inflate the layout once inside the onCreate()
at the beginning?
android android-activity activity-lifecycle
android android-activity activity-lifecycle
edited Nov 14 '18 at 9:06
Utkarsh Srivastava
130111
130111
asked Nov 14 '18 at 9:04
user9644796
1
It really depends on what you expect from the activity. Do you have work that needs to be done everytime the activity is shown? Or just once at the creation of the activity?
– Luca Nicoletti
Nov 14 '18 at 9:07
3
one-time initialization goes in onCreate, some times initialization of stuff can go in onResume depending on what you need as Luca said. Most of the code is usually in event listeners such as onClick for the UI click events. onResume is usually reserved for registering listeners and callbacks, unless you're doing something special. There will be many cases where you have an activity that does not override onResume simply because there is no need
– Tim Castelijns
Nov 14 '18 at 9:08
1
initialization of resources and variables should be done in onCreate(). because, when the Activity goes into onPause() or onStop() the onResume() will be call and the same variables and resource will be initialized and memory will be wasted. If your logic to run every time when the activity goes into background and come back to foreground, based on priority write the logic in onStart() and onResume().
– Chethan Kumar
Nov 14 '18 at 9:15
Thanks guys I understood it better now. Just a beginner's misunderstanding
– user9644796
Nov 14 '18 at 9:23
add a comment |
1
It really depends on what you expect from the activity. Do you have work that needs to be done everytime the activity is shown? Or just once at the creation of the activity?
– Luca Nicoletti
Nov 14 '18 at 9:07
3
one-time initialization goes in onCreate, some times initialization of stuff can go in onResume depending on what you need as Luca said. Most of the code is usually in event listeners such as onClick for the UI click events. onResume is usually reserved for registering listeners and callbacks, unless you're doing something special. There will be many cases where you have an activity that does not override onResume simply because there is no need
– Tim Castelijns
Nov 14 '18 at 9:08
1
initialization of resources and variables should be done in onCreate(). because, when the Activity goes into onPause() or onStop() the onResume() will be call and the same variables and resource will be initialized and memory will be wasted. If your logic to run every time when the activity goes into background and come back to foreground, based on priority write the logic in onStart() and onResume().
– Chethan Kumar
Nov 14 '18 at 9:15
Thanks guys I understood it better now. Just a beginner's misunderstanding
– user9644796
Nov 14 '18 at 9:23
1
1
It really depends on what you expect from the activity. Do you have work that needs to be done everytime the activity is shown? Or just once at the creation of the activity?
– Luca Nicoletti
Nov 14 '18 at 9:07
It really depends on what you expect from the activity. Do you have work that needs to be done everytime the activity is shown? Or just once at the creation of the activity?
– Luca Nicoletti
Nov 14 '18 at 9:07
3
3
one-time initialization goes in onCreate, some times initialization of stuff can go in onResume depending on what you need as Luca said. Most of the code is usually in event listeners such as onClick for the UI click events. onResume is usually reserved for registering listeners and callbacks, unless you're doing something special. There will be many cases where you have an activity that does not override onResume simply because there is no need
– Tim Castelijns
Nov 14 '18 at 9:08
one-time initialization goes in onCreate, some times initialization of stuff can go in onResume depending on what you need as Luca said. Most of the code is usually in event listeners such as onClick for the UI click events. onResume is usually reserved for registering listeners and callbacks, unless you're doing something special. There will be many cases where you have an activity that does not override onResume simply because there is no need
– Tim Castelijns
Nov 14 '18 at 9:08
1
1
initialization of resources and variables should be done in onCreate(). because, when the Activity goes into onPause() or onStop() the onResume() will be call and the same variables and resource will be initialized and memory will be wasted. If your logic to run every time when the activity goes into background and come back to foreground, based on priority write the logic in onStart() and onResume().
– Chethan Kumar
Nov 14 '18 at 9:15
initialization of resources and variables should be done in onCreate(). because, when the Activity goes into onPause() or onStop() the onResume() will be call and the same variables and resource will be initialized and memory will be wasted. If your logic to run every time when the activity goes into background and come back to foreground, based on priority write the logic in onStart() and onResume().
– Chethan Kumar
Nov 14 '18 at 9:15
Thanks guys I understood it better now. Just a beginner's misunderstanding
– user9644796
Nov 14 '18 at 9:23
Thanks guys I understood it better now. Just a beginner's misunderstanding
– user9644796
Nov 14 '18 at 9:23
add a comment |
1 Answer
1
active
oldest
votes
Please Refer the site for the better understanding of the activity lifecycle
https://developer.android.com/guide/components/activities/activity-lifecycle
and also this for brief understanding
https://www.javatpoint.com/android-life-cycle-of-activity
Now answering your question onCreate() is not just for inflating the layout.
The main part of the core logic is written here and onResume() is called when you minimize the or open the app once again it is called again and again but onCreate() is called once untill and unless the control is not forwarded to another activity
Like in Java the start running from
public static void main(String args)
In Android(Activity) the first line will be executed will be from onCreate() and not from the onResume()
if you will practice the same and will habitual of this process again and again then you better understand what i m trying to tell nothing can be more useful than you practice and your understanding try to print the toast or Log on each and every state of the activity lifecycle and you better understand this without the help of anyone
Cheers Happy Coding!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296403%2funderstanding-activity-lifecycle%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Please Refer the site for the better understanding of the activity lifecycle
https://developer.android.com/guide/components/activities/activity-lifecycle
and also this for brief understanding
https://www.javatpoint.com/android-life-cycle-of-activity
Now answering your question onCreate() is not just for inflating the layout.
The main part of the core logic is written here and onResume() is called when you minimize the or open the app once again it is called again and again but onCreate() is called once untill and unless the control is not forwarded to another activity
Like in Java the start running from
public static void main(String args)
In Android(Activity) the first line will be executed will be from onCreate() and not from the onResume()
if you will practice the same and will habitual of this process again and again then you better understand what i m trying to tell nothing can be more useful than you practice and your understanding try to print the toast or Log on each and every state of the activity lifecycle and you better understand this without the help of anyone
Cheers Happy Coding!
add a comment |
Please Refer the site for the better understanding of the activity lifecycle
https://developer.android.com/guide/components/activities/activity-lifecycle
and also this for brief understanding
https://www.javatpoint.com/android-life-cycle-of-activity
Now answering your question onCreate() is not just for inflating the layout.
The main part of the core logic is written here and onResume() is called when you minimize the or open the app once again it is called again and again but onCreate() is called once untill and unless the control is not forwarded to another activity
Like in Java the start running from
public static void main(String args)
In Android(Activity) the first line will be executed will be from onCreate() and not from the onResume()
if you will practice the same and will habitual of this process again and again then you better understand what i m trying to tell nothing can be more useful than you practice and your understanding try to print the toast or Log on each and every state of the activity lifecycle and you better understand this without the help of anyone
Cheers Happy Coding!
add a comment |
Please Refer the site for the better understanding of the activity lifecycle
https://developer.android.com/guide/components/activities/activity-lifecycle
and also this for brief understanding
https://www.javatpoint.com/android-life-cycle-of-activity
Now answering your question onCreate() is not just for inflating the layout.
The main part of the core logic is written here and onResume() is called when you minimize the or open the app once again it is called again and again but onCreate() is called once untill and unless the control is not forwarded to another activity
Like in Java the start running from
public static void main(String args)
In Android(Activity) the first line will be executed will be from onCreate() and not from the onResume()
if you will practice the same and will habitual of this process again and again then you better understand what i m trying to tell nothing can be more useful than you practice and your understanding try to print the toast or Log on each and every state of the activity lifecycle and you better understand this without the help of anyone
Cheers Happy Coding!
Please Refer the site for the better understanding of the activity lifecycle
https://developer.android.com/guide/components/activities/activity-lifecycle
and also this for brief understanding
https://www.javatpoint.com/android-life-cycle-of-activity
Now answering your question onCreate() is not just for inflating the layout.
The main part of the core logic is written here and onResume() is called when you minimize the or open the app once again it is called again and again but onCreate() is called once untill and unless the control is not forwarded to another activity
Like in Java the start running from
public static void main(String args)
In Android(Activity) the first line will be executed will be from onCreate() and not from the onResume()
if you will practice the same and will habitual of this process again and again then you better understand what i m trying to tell nothing can be more useful than you practice and your understanding try to print the toast or Log on each and every state of the activity lifecycle and you better understand this without the help of anyone
Cheers Happy Coding!
edited Nov 14 '18 at 9:24
answered Nov 14 '18 at 9:17
Utkarsh SrivastavaUtkarsh Srivastava
130111
130111
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296403%2funderstanding-activity-lifecycle%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
It really depends on what you expect from the activity. Do you have work that needs to be done everytime the activity is shown? Or just once at the creation of the activity?
– Luca Nicoletti
Nov 14 '18 at 9:07
3
one-time initialization goes in onCreate, some times initialization of stuff can go in onResume depending on what you need as Luca said. Most of the code is usually in event listeners such as onClick for the UI click events. onResume is usually reserved for registering listeners and callbacks, unless you're doing something special. There will be many cases where you have an activity that does not override onResume simply because there is no need
– Tim Castelijns
Nov 14 '18 at 9:08
1
initialization of resources and variables should be done in onCreate(). because, when the Activity goes into onPause() or onStop() the onResume() will be call and the same variables and resource will be initialized and memory will be wasted. If your logic to run every time when the activity goes into background and come back to foreground, based on priority write the logic in onStart() and onResume().
– Chethan Kumar
Nov 14 '18 at 9:15
Thanks guys I understood it better now. Just a beginner's misunderstanding
– user9644796
Nov 14 '18 at 9:23