<commit_before>package com.example.ddmeng.helloactivityandfragment.fragment;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.widget.CompoundButton;
import android.widget.FrameLayout;

import com.example.ddmeng.helloactivityandfragment.R;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnCheckedChanged;

public class FragmentBasicActivity extends Activity {
    private static final String LOG_TAG = FragmentBasicActivity.class.getSimpleName();
    private FragmentB fragmentB;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.i(LOG_TAG, this.getClass().getSimpleName() + " onCreate()");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_basic_activity_layout);
        ButterKnife.inject(this);
    }

    @OnCheckedChanged(R.id.fragment_b_control_toggle)
    void toggleFragmentB(CompoundButton toggleButton, boolean checked) {
        Log.d(LOG_TAG, "toggle " + checked);
        if (checked) {
            addFragmentB();
        } else {
            removeFragmentB();
        }

    }

    private void addFragmentB() {
        //You can also add/remove fragment dynamically
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentB = new FragmentB();
        fragmentTransaction.add(R.id.fragment_container, fragmentB);
        fragmentTransaction.commit();
    }

    private void removeFragmentB() {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.remove(fragmentB);
        fragmentTransaction.commit();
    }


    @Override
    protected void onRestart() {
        Log.i(LOG_TAG, this.getClass().getSimpleName() + " onRestart()");
        super.onRestart();<commit_msg>comment bug on fragment when turn on Do not keep activities<commit_after>package com.example.ddmeng.helloactivityandfragment.fragment;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.widget.CompoundButton;
import android.widget.FrameLayout;

import com.example.ddmeng.helloactivityandfragment.R;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnCheckedChanged;

public class FragmentBasicActivity extends Activity {
    private static final String LOG_TAG = FragmentBasicActivity.class.getSimpleName();
    private FragmentB fragmentB;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.i(LOG_TAG, this.getClass().getSimpleName() + " onCreate()");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_basic_activity_layout);
        ButterKnife.inject(this);
    }

    @OnCheckedChanged(R.id.fragment_b_control_toggle)
    void toggleFragmentB(CompoundButton toggleButton, boolean checked) {
        Log.d(LOG_TAG, "toggle " + checked);
        //this will have bug when "Do no keep activities" turned on
        //because, when the FragmentB is shown, home exit and enter again, the system auto recover the fragment
        //the checked status is also recovered, this method will invoke once, with the checked is true
        //So, the fragmentB is added twice, and remove button can only remove one of them
        if (checked) {
            addFragmentB();
        } else {
            removeFragmentB();
        }

    }

    private void addFragmentB() {
        //You can also add/remove fragment dynamically
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentB = new FragmentB();
        fragmentTransaction.add(R.id.fragment_container, fragmentB);
        fragmentTransaction.commit();
    }

    private void removeFragmentB() {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.remove(fragmentB);
        fragmentTransaction.commit();
    }


    @Override
    protected void onRestart() {
        Log.i(LOG_TAG, this.getClass().getSimpleName() + " onRestart()");
        super.onRestart();
{'fraction_non_alphanumeric': 0.0869276708692767, 'fraction_numerical': 0.0, 'mean_word_length': 3.652263374485597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7665522', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1128, 'n_words': 274}