Method onRestart() don't execute code when call method finish() on method on onStart()












0














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 ()?










share|improve this question
























  • 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
















0














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 ()?










share|improve this question
























  • 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














0












0








0







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 ()?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer























  • 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











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
});


}
});














draft saved

draft discarded


















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









0














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.






share|improve this answer























  • 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
















0














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.






share|improve this answer























  • 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














0












0








0






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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules