• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps My fragments does not disappear?

coinage23

Lurker
Hey!

So in my app I've got a button that should start a new activity. And when I do that, i want all the fragments gone from the first activity. I don't want to see them in my second activity. But, since i'm creating this thread, the fragments are still there.

Could someone explain how it works?

My code is here, from the mainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}



ArticleFragment frag = new ArticleFragment();
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction = manager.beginTransaction();
transaction.add(R.id.fragmentet,frag,"tagg");
transaction.commit();
//above, I add the fragment to the activity

}

public void WalkForward(View view)
{

FragmentManager manager = getSupportFragmentManager();
ArticleFragment f1 = (ArticleFragment) manager.findFragmentByTag("tagg");
FragmentTransaction transaction = manager.beginTransaction();

transaction.remove(f1);
transaction.commit();

// above, It should remove the fragment, right?

Intent intenten = new Intent(this, SecondActivity.class);
startActivity(intenten);

finish();

}


Any ideas? Thanks in advance
 
Back
Top Bottom