2

I am using Android annotation to create SharedPreferences in Android project.

AppPreferences

public interface CommonPref {
@DefaultString("")
String deviceId();

@DefaultString("NA")
String clientId();

@DefaultString("NA")
String accessToken();

@DefaultString("NA")
String refreshToken();

@DefaultString("NA")
String devToken();
}

When I am trying to access or filling these values from a class extended by android.app.Application It's throwing an error. Here is my code:

SuppressLint("Registered")
@EApplication
public class SampleApp extends Application {

public static CommonPref_ cprefs;

@Override
public void onCreate() {
    super.onCreate();
    cprefs = new CommonPrefs_(this);
}

I thought it's related to Applicaiton because Android annotation is the last process to execute when we build the project (may be before than Applicaiton files).

I tried to access the preference in activity file but it's throwing me same error i.e. Error:(25, 5) error: cannot find symbol class CommonPref_

The steps I followed to integrate it:

  • Downloaded the dependencies
  • Wrote the interface for preferences

Am I missing something?

Community
  • 1
  • 1
Prerna Rawat
  • 151
  • 1
  • 12

1 Answers1

1

Use @Pref in SampleApp class instead of instantiating generated pref.

@Pref
CommonPref_ cprefs;

Access deviceId by using

cprefs.deviceId().get();
degendra
  • 335
  • 1
  • 4
  • 11