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("onRestart\n");
}

The question is. How do I make the button send the application to onStop ()?

user48571
  • 27
  • 8

1 Answers1

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.

Notsileous
  • 548
  • 3
  • 9
  • i see this link https://stackoverflow.com/questions/10847526/what-exactly-activity-finish-method-is-doing – 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