Ciclo Activity android

Asked

Viewed 45 times

1

My app has 4 Activitys.
When I get to the Activity number 4 user has option to return to Activity number 2 that this in onStop().
The problem is that when I go back to Activity number 2 she runs again the onCreate(), creating a new Activity.
I need you to run only the onStart().

 imgeditarproduto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), ProdutosActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });

In short, I want to get back from Activity number 4 for Activity number 2.

3 answers

1

I created a Global variable that returns a boolean, every time Activity executes the method onRestart() execute a if checking the status of the variable if it is true runs the method again finish()

   @Override
    protected void onRestart() {
        super.onRestart();

           if(Globais.result == true){
               Globais.result = false;
               finish();
           }
    }

0

Another way to resolve this issue is you can call the Activity 3 for Activity 4 using the startActivityForResult and in the Activity 4, when killing the class instance, it will fall into the method onActivityResult before the onResume and of onStart.

Remember that the method onActivityResult shall be superscripted in Activity 3 and from there you can do whatever you want, as for example call the finish() going back like this to Activity 2.

0

The line intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); is it really necessary? Try taking it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.