Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // getting the toggle button state using shared preference
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
- Boolean runstopChecked = sharedPreferences.getBoolean("pref_runstop", false);
- viewHolder.tbtnJobRunStop.setChecked(runstopChecked);
- // Saving the position and toggle button state
- viewHolder.tbtnJobRunStop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
- SharedPreferences.Editor editor = sharedPreferences.edit();
- editor.putInt("pref_runstopposition", position);
- if(isChecked)
- {
- runJobId = dataModel.getJobId();
- editor.putBoolean("pref_runstop", true);
- editor.apply();
- Intent statusIntent = new Intent(getContext(), RefreshJobService.class);
- statusIntent.putExtra("id", runJobId);
- getContext().startService(statusIntent);
- } else
- {
- stopJobId = dataModel.getJobId();
- editor.putBoolean("pref_runstop", false);
- editor.apply();
- stopJob stopjob = new stopJob();
- stopjob.execute();
- Intent i = new Intent("stopjob");
- LocalBroadcastManager.getInstance(getContext()).sendBroadcast(i);
- i.putExtra("stopJobId",stopJobId);
- getContext().sendBroadcast(i);
- }
- }
- });
Add Comment
Please, Sign In to add comment