Method onRestart() don't execute code when call method finish() on method on onStart()
The method "sendSave" closes the application, but when I go to andorid to reopen the application the code of the onRestart () method does not execute in the terminal.
Code:
protected void onStart() {
exitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
exitNotSave(view);
finish();
}
});
}
public void exitNotSave(View a){
....
}
@Override
protected void onRestart() {
super.onRestart();
setContentView(R.layout.activity_simplenotes);
System.out.println("onRestartn");
}
The question is. How do I make the button send the application to onStop ()?
android methods
add a comment |
The method "sendSave" closes the application, but when I go to andorid to reopen the application the code of the onRestart () method does not execute in the terminal.
Code:
protected void onStart() {
exitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
exitNotSave(view);
finish();
}
});
}
public void exitNotSave(View a){
....
}
@Override
protected void onRestart() {
super.onRestart();
setContentView(R.layout.activity_simplenotes);
System.out.println("onRestartn");
}
The question is. How do I make the button send the application to onStop ()?
android methods
Please read carefully developer.android.com/guide/components/activities/…
– Stanislav Bondar
Nov 19 '18 at 15:59
why do you expect it to call onRestart? Do you know what finish() does?
– Tim Castelijns
Nov 19 '18 at 16:00
if is this correct stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:03
if what is correct? There are a ton of answers in that link
– Tim Castelijns
Nov 19 '18 at 16:09
add a comment |
The method "sendSave" closes the application, but when I go to andorid to reopen the application the code of the onRestart () method does not execute in the terminal.
Code:
protected void onStart() {
exitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
exitNotSave(view);
finish();
}
});
}
public void exitNotSave(View a){
....
}
@Override
protected void onRestart() {
super.onRestart();
setContentView(R.layout.activity_simplenotes);
System.out.println("onRestartn");
}
The question is. How do I make the button send the application to onStop ()?
android methods
The method "sendSave" closes the application, but when I go to andorid to reopen the application the code of the onRestart () method does not execute in the terminal.
Code:
protected void onStart() {
exitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
exitNotSave(view);
finish();
}
});
}
public void exitNotSave(View a){
....
}
@Override
protected void onRestart() {
super.onRestart();
setContentView(R.layout.activity_simplenotes);
System.out.println("onRestartn");
}
The question is. How do I make the button send the application to onStop ()?
android methods
android methods
edited Nov 19 '18 at 16:27
asked Nov 19 '18 at 15:54
user48571
167
167
Please read carefully developer.android.com/guide/components/activities/…
– Stanislav Bondar
Nov 19 '18 at 15:59
why do you expect it to call onRestart? Do you know what finish() does?
– Tim Castelijns
Nov 19 '18 at 16:00
if is this correct stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:03
if what is correct? There are a ton of answers in that link
– Tim Castelijns
Nov 19 '18 at 16:09
add a comment |
Please read carefully developer.android.com/guide/components/activities/…
– Stanislav Bondar
Nov 19 '18 at 15:59
why do you expect it to call onRestart? Do you know what finish() does?
– Tim Castelijns
Nov 19 '18 at 16:00
if is this correct stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:03
if what is correct? There are a ton of answers in that link
– Tim Castelijns
Nov 19 '18 at 16:09
Please read carefully developer.android.com/guide/components/activities/…
– Stanislav Bondar
Nov 19 '18 at 15:59
Please read carefully developer.android.com/guide/components/activities/…
– Stanislav Bondar
Nov 19 '18 at 15:59
why do you expect it to call onRestart? Do you know what finish() does?
– Tim Castelijns
Nov 19 '18 at 16:00
why do you expect it to call onRestart? Do you know what finish() does?
– Tim Castelijns
Nov 19 '18 at 16:00
if is this correct stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:03
if is this correct stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:03
if what is correct? There are a ton of answers in that link
– Tim Castelijns
Nov 19 '18 at 16:09
if what is correct? There are a ton of answers in that link
– Tim Castelijns
Nov 19 '18 at 16:09
add a comment |
1 Answer
1
active
oldest
votes
Take a look at https://developer.android.com/guide/components/activities/activity-lifecycle for the activity lifecycle. When you call Finish(), you are invoking onDestroy(), which as you can see in the lifecycle chart is called after any onRestart triggers.
If you want to trigger onRestart, it needs to be stopped first, which I believe would entail closing the activity with the home button.
Not sure what your overall goal is but look over the activity lifecycle chart first.
edit
If the application is closing when you call Finish(), it means you have no other activity on the backstack and this current one is destroyed. When the app opens again it will be creating that activity anew, meaning onStart and onResume will be called.
i see this link stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:07
And? Please use complete thoughts if you want help. Finish() destroys the activity, you cant restart an activity that has been destroyed.
– Notsileous
Nov 19 '18 at 16:11
I need the button to close the application but then when it reopens (not restart application. Is when I go to the history of open applications (when I see a list)) I want it to start at the point where it stopped (get the text to the Textview)
– user48571
Nov 19 '18 at 16:15
It doesnt work like that, if you close the app with Finish(), code will run in onLoad and onResume same it did the first time it opened. You cant expect your data to magically persist after you remove your only activity unless you store it some fashion.
– Notsileous
Nov 19 '18 at 16:25
What I need is. How do I make the button send the application to onStop (). just this
– user48571
Nov 19 '18 at 16:29
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%2f53378336%2fmethod-onrestart-dont-execute-code-when-call-method-finish-on-method-on-ons%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
Take a look at https://developer.android.com/guide/components/activities/activity-lifecycle for the activity lifecycle. When you call Finish(), you are invoking onDestroy(), which as you can see in the lifecycle chart is called after any onRestart triggers.
If you want to trigger onRestart, it needs to be stopped first, which I believe would entail closing the activity with the home button.
Not sure what your overall goal is but look over the activity lifecycle chart first.
edit
If the application is closing when you call Finish(), it means you have no other activity on the backstack and this current one is destroyed. When the app opens again it will be creating that activity anew, meaning onStart and onResume will be called.
i see this link stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:07
And? Please use complete thoughts if you want help. Finish() destroys the activity, you cant restart an activity that has been destroyed.
– Notsileous
Nov 19 '18 at 16:11
I need the button to close the application but then when it reopens (not restart application. Is when I go to the history of open applications (when I see a list)) I want it to start at the point where it stopped (get the text to the Textview)
– user48571
Nov 19 '18 at 16:15
It doesnt work like that, if you close the app with Finish(), code will run in onLoad and onResume same it did the first time it opened. You cant expect your data to magically persist after you remove your only activity unless you store it some fashion.
– Notsileous
Nov 19 '18 at 16:25
What I need is. How do I make the button send the application to onStop (). just this
– user48571
Nov 19 '18 at 16:29
add a comment |
Take a look at https://developer.android.com/guide/components/activities/activity-lifecycle for the activity lifecycle. When you call Finish(), you are invoking onDestroy(), which as you can see in the lifecycle chart is called after any onRestart triggers.
If you want to trigger onRestart, it needs to be stopped first, which I believe would entail closing the activity with the home button.
Not sure what your overall goal is but look over the activity lifecycle chart first.
edit
If the application is closing when you call Finish(), it means you have no other activity on the backstack and this current one is destroyed. When the app opens again it will be creating that activity anew, meaning onStart and onResume will be called.
i see this link stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:07
And? Please use complete thoughts if you want help. Finish() destroys the activity, you cant restart an activity that has been destroyed.
– Notsileous
Nov 19 '18 at 16:11
I need the button to close the application but then when it reopens (not restart application. Is when I go to the history of open applications (when I see a list)) I want it to start at the point where it stopped (get the text to the Textview)
– user48571
Nov 19 '18 at 16:15
It doesnt work like that, if you close the app with Finish(), code will run in onLoad and onResume same it did the first time it opened. You cant expect your data to magically persist after you remove your only activity unless you store it some fashion.
– Notsileous
Nov 19 '18 at 16:25
What I need is. How do I make the button send the application to onStop (). just this
– user48571
Nov 19 '18 at 16:29
add a comment |
Take a look at https://developer.android.com/guide/components/activities/activity-lifecycle for the activity lifecycle. When you call Finish(), you are invoking onDestroy(), which as you can see in the lifecycle chart is called after any onRestart triggers.
If you want to trigger onRestart, it needs to be stopped first, which I believe would entail closing the activity with the home button.
Not sure what your overall goal is but look over the activity lifecycle chart first.
edit
If the application is closing when you call Finish(), it means you have no other activity on the backstack and this current one is destroyed. When the app opens again it will be creating that activity anew, meaning onStart and onResume will be called.
Take a look at https://developer.android.com/guide/components/activities/activity-lifecycle for the activity lifecycle. When you call Finish(), you are invoking onDestroy(), which as you can see in the lifecycle chart is called after any onRestart triggers.
If you want to trigger onRestart, it needs to be stopped first, which I believe would entail closing the activity with the home button.
Not sure what your overall goal is but look over the activity lifecycle chart first.
edit
If the application is closing when you call Finish(), it means you have no other activity on the backstack and this current one is destroyed. When the app opens again it will be creating that activity anew, meaning onStart and onResume will be called.
edited Nov 19 '18 at 16:08
answered Nov 19 '18 at 16:05
Notsileous
22818
22818
i see this link stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:07
And? Please use complete thoughts if you want help. Finish() destroys the activity, you cant restart an activity that has been destroyed.
– Notsileous
Nov 19 '18 at 16:11
I need the button to close the application but then when it reopens (not restart application. Is when I go to the history of open applications (when I see a list)) I want it to start at the point where it stopped (get the text to the Textview)
– user48571
Nov 19 '18 at 16:15
It doesnt work like that, if you close the app with Finish(), code will run in onLoad and onResume same it did the first time it opened. You cant expect your data to magically persist after you remove your only activity unless you store it some fashion.
– Notsileous
Nov 19 '18 at 16:25
What I need is. How do I make the button send the application to onStop (). just this
– user48571
Nov 19 '18 at 16:29
add a comment |
i see this link stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:07
And? Please use complete thoughts if you want help. Finish() destroys the activity, you cant restart an activity that has been destroyed.
– Notsileous
Nov 19 '18 at 16:11
I need the button to close the application but then when it reopens (not restart application. Is when I go to the history of open applications (when I see a list)) I want it to start at the point where it stopped (get the text to the Textview)
– user48571
Nov 19 '18 at 16:15
It doesnt work like that, if you close the app with Finish(), code will run in onLoad and onResume same it did the first time it opened. You cant expect your data to magically persist after you remove your only activity unless you store it some fashion.
– Notsileous
Nov 19 '18 at 16:25
What I need is. How do I make the button send the application to onStop (). just this
– user48571
Nov 19 '18 at 16:29
i see this link stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:07
i see this link stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:07
And? Please use complete thoughts if you want help. Finish() destroys the activity, you cant restart an activity that has been destroyed.
– Notsileous
Nov 19 '18 at 16:11
And? Please use complete thoughts if you want help. Finish() destroys the activity, you cant restart an activity that has been destroyed.
– Notsileous
Nov 19 '18 at 16:11
I need the button to close the application but then when it reopens (not restart application. Is when I go to the history of open applications (when I see a list)) I want it to start at the point where it stopped (get the text to the Textview)
– user48571
Nov 19 '18 at 16:15
I need the button to close the application but then when it reopens (not restart application. Is when I go to the history of open applications (when I see a list)) I want it to start at the point where it stopped (get the text to the Textview)
– user48571
Nov 19 '18 at 16:15
It doesnt work like that, if you close the app with Finish(), code will run in onLoad and onResume same it did the first time it opened. You cant expect your data to magically persist after you remove your only activity unless you store it some fashion.
– Notsileous
Nov 19 '18 at 16:25
It doesnt work like that, if you close the app with Finish(), code will run in onLoad and onResume same it did the first time it opened. You cant expect your data to magically persist after you remove your only activity unless you store it some fashion.
– Notsileous
Nov 19 '18 at 16:25
What I need is. How do I make the button send the application to onStop (). just this
– user48571
Nov 19 '18 at 16:29
What I need is. How do I make the button send the application to onStop (). just this
– user48571
Nov 19 '18 at 16:29
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53378336%2fmethod-onrestart-dont-execute-code-when-call-method-finish-on-method-on-ons%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
Please read carefully developer.android.com/guide/components/activities/…
– Stanislav Bondar
Nov 19 '18 at 15:59
why do you expect it to call onRestart? Do you know what finish() does?
– Tim Castelijns
Nov 19 '18 at 16:00
if is this correct stackoverflow.com/questions/10847526/…
– user48571
Nov 19 '18 at 16:03
if what is correct? There are a ton of answers in that link
– Tim Castelijns
Nov 19 '18 at 16:09