For study I've been working on an app for a thermostat which has a couple of features. One of these features is that one can set their day schedule. So I've got a screen which displays all days visually. To alter these, a button opens up a new activity which enables the user to adjust the run of the day.
Now I've got the sending objects containing the schedules from the week to the dayscreen figured and worked out. However, when leaving the dayscreen, the schedule needs to be send back as well. That, is where I have a problem.
WeekScreen, the method below creates the intent
@Override
public void onClick(View view) {
dayScheduleIntent = new Intent(WeekScheduleScreen.this.getBaseContext(), DayScheduleScreen.class);
Serializable switches = weekschedule.Get(daynumber);
dayScheduleIntent.putExtra("daySchedule", switches);
startActivity(dayScheduleIntent);
}
DayScheduleScreen, here is where it reads out
DaySchedule daySchedule = getIntent().getSerializableExtra("daySchedule");
So far so good. But backwards doesn't work
DayScheduleScreen, located in OnBackPressed
intent.putExtra("daySchedule",(Serializable)daySchedule.GetSwitches());
WeekScreen, located in OnResume
(DaySchedule)dayScheduleIntent.getSerializableExtra("daySchedule");
I've tried a lot. But I'm completely stumped. While the putExtra actually works in the DayScheduleScreen, in the Weekscreen it never arrived and I can't use the direct reference either as it appears to make a copy when retrieving from the intent. So, how can I get the altered data back to the Weekscreen? Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire