Return to Fragment Blank

Asked

Viewed 45 times

0

I’m using Navigation Bottom in intent main and inserted a Alert customized on another screen to return to her, however, when I return the screen is blank, you know how I can solve this? I thank you already.

Follow the code of my main class:

public class MainActivity extends AppCompatActivity {

    private Toolbar mToolbar;

    private BottomNavigationView mBottomNavigationView;
    private TextView mTitle_Toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        hideItemMenu();
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mTitle_Toolbar = (TextView) findViewById(R.id.title_toolbar);

        mBottomNavigationView.setOnNavigationItemSelectedListener
                (new BottomNavigationView.OnNavigationItemSelectedListener() {
                    @Override
                    public boolean onNavigationItemSelected( MenuItem item) {
                        Fragment selectedFragment = null;
                        switch (item.getItemId()) {
                            case R.id.action_item1:
                                mTitle_Toolbar.setText(getString(R.string.tab_call));
                                //mToolbar.setLogo(R.mipmap.ic_reorder_white_24dp);
                                selectedFragment = CalledFragment.newInstance();
                                break;
                            case R.id.action_item2:
                                mTitle_Toolbar.setText(getString(R.string.tab_scale));
                                //mToolbar.setLogo(R.mipmap.ic_assignment_turned_in_white_24dp);
                                selectedFragment = ScaleFragment.newInstance();
                                break;
                            case R.id.action_item3:
                                mTitle_Toolbar.setText(getString(R.string.tab_perfil));
                                //mToolbar.setLogo(R.mipmap.ic_account_box_white_24dp);
                                selectedFragment = Profilefragment.newInstance();
                                break;
                        }
//                        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
//                        transaction.replace(R.id.frame_layout, selectedFragment);
//                        transaction.commit();
                        return true;
                    }
                });
            mBottomNavigationView.setSelectedItemId(0);
    }

    private void hideItemMenu() {
        mBottomNavigationView = (BottomNavigationView) findViewById(R.id.navigation);
        Menu navMenu = mBottomNavigationView.getMenu();
        navMenu.findItem(R.id.action_item2).setVisible(false);
    }

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

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

        //Manually displaying the first fragment - one time only
        mTitle_Toolbar.setText(getString(R.string.tab_call));
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.frame_layout, CalledFragment.newInstance());
        transaction.commit();
    }

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

        Log.i("TAG", "voltando para Main");
    }
}

The Event that should return to her:

mDialog.getBtnAprove().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mDialog.dismiss();
            mContext.startActivity(new Intent(mContext, MainActivity.class));
            mAct.finish();
        }
    });

1 answer

0

I found a solution:

Insert a flag in the Intent: Intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

vlw guys

Browser other questions tagged

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