Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- Button add_btn;
- TextView title_txt , priority_txt , id_txt;
- SharedPreferences preferences;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- add_btn = findViewById(R.id.add_btn);
- title_txt = findViewById(R.id.title_txt);
- priority_txt = findViewById(R.id.priority_txt);
- id_txt = findViewById(R.id.id_txt);
- add_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(MainActivity.this , AddTodoActivity.class);
- startActivity(intent);
- }
- });
- }
- @Override
- protected void onStart() {
- super.onStart();
- preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
- retreiveData();
- }
- private void retreiveData() {
- String title = preferences.getString("title" , "none");
- int id = preferences.getInt("id" , 0);
- boolean priority = preferences.getBoolean("priority" , false);
- title_txt.setText("Title : " + title);
- id_txt.setText("Id : " + id);
- if(priority){
- priority_txt.setText("Priority : High" );
- }else {
- priority_txt.setText("Priority : Low");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement