«   2018/09   »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
Archives
Today
274
Total
1,153,495
안정적인 DNS서비스 DNSEver
관리 메뉴

Blue Breeze

초기화 값 저장/호출 SharedPreferences 본문

Editor IDE/AndroidStudio

초기화 값 저장/호출 SharedPreferences

푸른바람 C/H 2017.01.23 08:30

public class MainActivity extends AppCompatActivity {
    ...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        init();
    }

    @Override
    protected void onResume() {
        SharedPreferences pref = getSharedPreferences("gostop",Activity.MODE_PRIVATE);
        keep = pref.getInt("keep",0);

        super.onResume();
    }

    @Override
    protected void onPause() {

        SharedPreferences pref = getSharedPreferences("lottoSetting", MainActivity.MODE_PRIVATE);
        SharedPreferences.Editor editor = pref.edit();
        editor.putInt("keep",keep);
        editor.commit();

        super.onPause();
    }
    ....
}


0 Comments
댓글쓰기 폼