Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Application
- public class BaseApplication extends Application {
- @Override
- public void onCreate() {
- super.onCreate();
- SharedPreferences pref = getSharedPreferences("settings", MODE_PRIVATE);
- SharedPreferences.Editor editor = pref.edit();
- editor.putString("display-name", "John Doe");
- editor.putBoolean("safe-mode", true);
- editor.apply();
- }
- }
- 2. Activity
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ButterKnife.bind(this);
- }
- @BindView(R.id.tvShowPreference) TextView tvShowPreference;
- @OnClick(R.id.btnGetPref)
- public void showPref(){
- SharedPreferences pref = getApplicationContext()
- .getSharedPreferences("settings", MODE_PRIVATE);
- this.displayname = pref.getString("display-name", "");
- this.tvShowPreference.setText(this.displayname);
- }
- 3. Android Manifest
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
- android:supportsRtl="true"
- android:theme="@style/AppTheme"
- android:name=".BaseApplication">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement