SharedPreferenceBase 클래스에 SharedPreference 를
DolistApplication 클래스의 static 참조변수 app을 이용해서
LaunchActivity에 사용하는데 nullPointException 뜨는데 도저히 모르겠네요.
도움 구해봅니다 ㅠ
public class SharedPreferenceBase {
private static final String SHARED_PREFERENCE_NAME = "com.example.manager";
public static SharedPreferences getSharedPreferences() {
try {
return DolistApplication.app.getSharedPreferences(SharedPreferenceBase.SHARED_PREFERENCE_NAME, Activity.MODE_PRIVATE);
}catch(NullPointerException e) {
return null;
}
}
/* 튜토리얼 bool 결정 메소드 */
public static void setTutorialShow(boolean fact) {
getSharedPreferences().edit().putBoolean(DolistApplication.app.TUTORIAL_CHECK, fact).apply();
}
public static boolean getTutorialShow() {
return getSharedPreferences().getBoolean(DolistApplication.app.TUTORIAL_CHECK, false);
}
}
액티비티 부분...
public class DolistApplication extends Application {
public static String TAG = "DolistApplication";
public final static String TUTORIAL_CHECK = "TutorialCheck";
private final static String CACHE_DEVICE_ID = "CacheDeviceID";
public static DolistApplication app;
@Override
public void onCreate() {
super.onCreate();
app = this;
}
public class LaunchActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);
Handler handler = new Handler();
// TODO DB 결정하고 개발 필요
/* SharedPreference bool값에 따라 분기 */
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent;
if (SharedPreferenceBase.getTutorialShow() == false) {
intent = new Intent(LaunchActivity.this, Tutorial.class);
SharedPreferenceBase.setTutorialShow(true);
}
else
intent = new Intent(LaunchActivity.this, DateMain.class);
Log.e("튜토리얼 : ", " " + SharedPreferenceBase.getTutorialShow());
startActivity(intent);
finish();
}
},2000);
}
}