Android search refreshes activity. I want to open a fragment on search
<p>I have an activity which comprises a custom toolbar, the toolbar contains SearchView. On querying search I am calling following :</p>

<pre><code>@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        Toolbar toolbar = (Toolbar) findViewById(R.id.dashboard_toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);

        drawerListNames = getResources().getStringArray(R.array.drawer_list);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawer = (LinearLayout) findViewById(R.id.left_drawer);
        mDrawerList = (ListView) mDrawerLayout.findViewById(R.id.drawer_list);

        sessionManager = ((RestroOwnerApplication) getApplicationContext()).getSessionManager();

        Intent intent = getIntent();
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            String query = intent.getStringExtra(SearchManager.QUERY);
            Fragment fragment = new SearchFragment();
            getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
//            Toast.makeText(Home.this, query, Toast.LENGTH_SHORT).show();
        }

        addDrawer();
        init();
    }
</code></pre>

<p>The fragment appears for a moment. After that activity gets refreshed and fragment disappears. It is reinitializing the activity. I have no idea what am I missing.</p>

<p>Edit: adding methods addDrawer() and init()</p>

<pre><code>    /**
     * Add drawer to dashboard home activity.
     */
    private void addDrawer() {
        mDrawerList.setAdapter(new ArrayAdapter&lt;&gt;(this, R.layout.drawer_list_item, drawerListNames));
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
        // ActionBarDrawerToggle ties together the the proper interactions
        // between the sliding drawer and the action bar app icon
        mDrawerToggle = new ActionBarDrawerToggle(
                this,                  /* host Activity */
                mDrawerLayout,         /* DrawerLayout object */
                R.string.drawer_open,  /* "open drawer" description for accessibility */
                R.string.drawer_close  /* "close drawer" description for accessibility */
        ) {
            public void onDrawerClosed(View view) {
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            public void onDrawerOpened(View drawerView) {
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };
        mDrawerToggle.setDrawerIndicatorEnabled(true);
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        final ImageButton navDrawerToggle = (ImageButton) findViewById(R.id.nav_drawer_toggle);
        navDrawerToggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final InputMethodManager imm = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(navDrawerToggle.getWindowToken(), 0);
                mDrawerLayout.openDrawer(GravityCompat.START);
            }
        });
    }

    /**
     * Initialize home screen
     */
    private void init() {
        synchronizeArticles();
    }

    /**
     * Synchronize articles
     */
    private void synchronizeArticles() {
        RestroOwnerApplication restroOwnerApplicationContext =
                (RestroOwnerApplication) this.getApplicationContext();
        this.articleManager = restroOwnerApplicationContext.getArticleManager();
        articleManager.setOnSyncCompletionListener(new ArticleManager.OnSyncCompletionListener() {
            @Override
            public void onSyncCompletion() {
                goTo("browse");
            }
        });
        articleManager.syncArticles();
    }
</code></pre>

<p>Edit : demo video
<a href="https://www.youtube.com/watch?v=Wvhv2jv-RmU" rel="nofollow">https://www.youtube.com/watch?v=Wvhv2jv-RmU</a></p>