HOW TO SAVE DATA WITH SHARED PREFERENCES IN A FRAGMENT : 1. Hi, I'm having a problem with saving data permanently. It should be simple, I'm sending data to another fragment and it works perfectly, however, I nearly have no idea how to save data.
2. So is this, but now follows a code block:

        /*package com.example.mskydraw.notetech;


        import android.os.Bundle;
        import android.support.v4.app.Fragment;
        import android.support.annotation.Nullable;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.app.Activity;
        import android.widget.Button;
        import android.widget.EditText;
        
        
        public class Cofo extends Fragment {
        
            private static EditText Txt;
        
            TopSectionListener activityCommander;
        
            public interface TopSectionListener{
        
                public void createMeme(String top);

            };
        
            @Override
            public void onAttach(Activity activity) {
                super.onAttach(activity);
                try {
            activityCommander = (TopSectionListener) activity;
                }catch (ClassCastException e){
                    throw new ClassCastException(activity.toString());
                }
            }

           @Override
            public View onCreateView(LayoutInflater inflater,@Nullable                  

        ViewGroup container, @Nullable
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_cofo,         
        container,false);

        Txt = (EditText) view.findViewById(R.id.Txt);
        final Button Btn = (Button) view.findViewById(R.id.Btn);


        Btn.setOnClickListener(
                new View.OnClickListener(){
                    public void onClick(View v){
                        buttonClicked(v);
                    };
                }
        );



        return  view;
    }


    // call this whenever the button is clicked!
    public void buttonClicked(View view){
        activityCommander.createMeme(Txt.getText().toString());
    };

} */

package com.example.mskydraw.notetech;


        import android.content.Context;
        import android.content.SharedPreferences;
        import android.os.Bundle;
        import android.support.v4.app.Fragment;
        import android.support.v4.app.FragmentManager;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.Button;
        import android.widget.EditText;
        import android.widget.Gallery;
        import android.widget.TextView;
        import android.widget.Toast;

        import java.io.FileOutputStream;

        import static android.content.Context.MODE_PRIVATE;


/**
 * A simple {@link Fragment} subclass.
 */
public class Cofo extends Fragment {

    final static String SHARED_NAME_STRING="sharedp";
    final static String USER_NAME_STRING="user";




    public Cofo() {
        // Required empty public constructor
    }

    EditText newTxt;
    Button newBtn;
    SharedPreferences sharedPreferences;
    Context c = getActivity();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_cofo, container, false);
        // finding my bouton and text on layout
        newTxt = (EditText)view.findViewById(R.id.Txt);
        newBtn = (Button)view.findViewById(R.id.Btn);



        sharedPreferences=this.c.getSharedPreferences(SHARED_NAME_STRING,Context.MODE_PRIVATE);
        String userNameString=sharedPreferences.getString(USER_NAME_STRING, "");

        newTxt.setText(userNameString);

        // whenever I click on the bouton
        newBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){


                //This code allows you to jump into another fragment
                // Call the fragment to where I want to jump
                Main_content newmain = new Main_content();

                //Here we are going to learn to how to save data
                String Message = newTxt.getText().toString();
                String file_name = "Hello_file";
                // Create an object output string


                //here we are sending data to another fragment
                //You have declare bundle
                Bundle bundle = new Bundle();
                // You can use bundle.putxx everything such as String...float..
                bundle.putInt("N1",5);
                //calling the fragment I'm going to send the data
                // and I'm going to send data I saved on bundle.
                newmain.setArguments(bundle);
                // The process of declaration fragment
                FragmentManager manager = getFragmentManager();
                // Jumping into main content fragment
                manager.beginTransaction().replace(R.id.fragment,newmain).commit();

                if (newTxt.getText().toString().equals("Hello")){
                    Toast.makeText(Cofo.this.getActivity(), "true", Toast.LENGTH_SHORT).show();
                }
                else{
                    Toast.makeText(Cofo.this.getActivity(), "Hi", Toast.LENGTH_SHORT).show();
                }

                SharedPreferences.Editor editor=sharedPreferences.edit();



            }
        });

        return view;
    }

}