As of Finish in past Activity

Asked

Viewed 128 times

0

Well I am with the following doubt, has to give finish() in fragment who have passed ?

The case is as follows:

I have a few screens in sequence where I use for the comrade to choose the snack, then he chooses the bread, clicks next, chooses the type of the steak clicks next, chooses if you want salad clicks next, all these times he can come back and choose again the product, but on the last screen when he clicks on effective sale, if he returns should be redirected to the first page, in the case of my example the page to choose the bread.

I tried to give a finish() at last fragment, but she comes back the previous one. In case I can not clear all navigation list because there are other restaurants to have access, so I should return to the option (in the example) of choice of bread.

Are basically 6 activity in which I can sail back and forth in the choice of bread

My attempt was to put on the event of onBackPressed() thus:

@Override
public void onBackPressed()
{
    try{
        super.onBackPressed();

        Intent intent = new Intent(getApplicationContext(),FragmentCardapio_.class);
        startActivity(intent);
    }catch(Exception e){
        MessageUtil.showError(getApplicationContext(), e.getMessage());

    }
}

But of error !

android.view.Windowmanager$Badtokenexception: Unable to add window -- token null is not for an application

  • tried to use Intent activitquequeroabrir = new Intent(...); and then activitquequeroabrir.startActivity();?

  • yes, I’ll update the question

  • @Armandomarquessobrinho update her

  • 2

    In one place talks about Fragments in another in activities. After all are activities or Fragments?

  • It’s because the first is fragment (fragment_caradapio) and the others are activitys

  • The error is because you are trying to launch an Activity by using in the class Intent that is a Fragment(FragmentCardapio_.class).

  • How do you fix it ?

  • opa, now vi, then in case, it would be better to Voce do all of them Fragments, because thus Voce has greater flexibility and a Fragment is also an Activity or works the same with the difference that Voce needs to use a fragmentmanager to call the respective routines, whether with dynamic layout or Static layout, in my view it is easier to handle, except if you really need to have an Activity

  • if in the case Voce is to use Fragment, take the example of navigation draw from android studio, it already opens and navigates between several native Fragments same

  • My problem is not navigating, this attending me very well, what I need is when Face click back, it goes to menu.

Show 5 more comments
No answers

Browser other questions tagged

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