앱 최초 실행여부 확인하기
java)
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 31 32 33 34 35 36 37 38 39 | package com.ghj.blog_031; import android.app.Activity; import android.content.SharedPreferences; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends AppCompatActivity { //UI TextView txtFirst; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //UI txtFirst = (TextView)findViewById(R.id.txtFirst); txtFirst.setText(""+CheckAppFirstExecute()); } //앱최초실행확인 (true - 최초실행) public boolean CheckAppFirstExecute(){ SharedPreferences pref = getSharedPreferences("IsFirst" , Activity.MODE_PRIVATE); boolean isFirst = pref.getBoolean("isFirst", false); if(!isFirst){ //최초 실행시 true 저장 SharedPreferences.Editor editor = pref.edit(); editor.putBoolean("isFirst", true); editor.commit(); } return !isFirst; } } | cs |
xml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:text="앱최초 실행여부 : " android:textSize="24dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/txtFirst" android:textSize="24dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> | cs |
결과
'IT > - 프로그래밍' 카테고리의 다른 글
안드로이드 좌표변환 도분초를 도(degree)로 변환 (0) | 2016.11.15 |
---|---|
안드로이드 Assets폴더에서 파일 읽어오기 (0) | 2016.11.14 |
안드로이드 2진수, 8진수, 16진수를 10진수로 변환 (0) | 2016.11.13 |
안드로이드 10진수를 2진수, 8진수, 16진수로 변환 (0) | 2016.11.13 |
안드로이드 와이파이 상태, 네트워크 상태 수신 (0) | 2016.11.12 |