-1

I have a main activity (M) (host activity) and few full page size fragments (f1,f2,f3).
My main activity is a empty page and I am not showing anything into it.
When my app starts, I am showing fragment f1 by default.
But when I am pressing back button I am landing on white page of my main activity (M).
I don't want activity M in my backstack. How can I remove that?
I tried intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); before activity started, but it's not working also I tried finish(); after start activity but it is also not working. Any Idea?

I have a problem about removing Mainactivity from back stack ..

When i press back button from specific fragment it lead me to a white page "content main" of my main activity (M).

huilo
  • 47
  • 5
  • the question should be like how should I remove the first fragment opened from backStack on backPressed Method – Rizwan Atta Jul 30 '18 at 16:27
  • please can you show the first screen shot when your app gets opened ? because from I am seeing your app opens a blank page at start! or something else! the question statement is VAGUE please be specific a little! thnx! – Rizwan Atta Jul 30 '18 at 16:30
  • I changed "the first fragment opened from backStack" by setting a specific fragment with { displaySelectedScreen(R.id.nav_camera); } ... So the first things stack in "backStack" is Mainactivity .. i want to remove it there whene i press back from an fragment .. – huilo Jul 30 '18 at 16:34
  • so got it if you want a back stack with your own style of code that you are using just see my answer I am gonna put ok? and hope that will help! – Rizwan Atta Jul 30 '18 at 16:41
  • hope also .. thx @Rizwanatta – huilo Jul 30 '18 at 16:46
  • try the edited answer! please – Rizwan Atta Jul 30 '18 at 17:05
  • No resolt .. the MainActivity "conten_main" still have "addToBackStack" and all fragment get replace with "content_frame"@Rizwanatta – huilo Jul 30 '18 at 17:11
  • check the edited version now – Rizwan Atta Jul 30 '18 at 17:26
  • it overlapp fragments @Rizwanatta – huilo Jul 30 '18 at 17:54

1 Answers1

0

If you don't want the fragment empty Activity M in the backstack, don't add fragment f1 to the backstack in your fragment transaction.

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.content_frame, fragment);
    ft.commit();

More info :

petey
  • 16,914
  • 6
  • 65
  • 97