Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Cleaning Your Code

Carlos Monteiro
PLUS
Carlos Monteiro
Courses Plus Student 4,758 Points

I loose my todo list items when device orientation changes.

Is there a better way to handle orientation changes within RxJava?

I do, too, sort of. The list still exists, but it is not visible until I add a new item, at which point the entire list reappears, with the new item. Can't figure out what's going on...

2 Answers

Xi Tao
Xi Tao
3,221 Points

That's one of the problems with the RxJava model, data is not shown until the data actually changes. So in this case after rotation no changes have been made to the data as a result there is no need to update the view, which is left blank. Now not only do you have to write a bunch of RxJava to push data to your views you still have to write a bunch of code to actually pull the data when you rebuild your view (on Rotation). Which makes RxJava sort of pointless in some situations. There are actually fewer push models of data that actually model your problem, and most of the time you can get away with a pull model.

The additional work to fix this problem is to code in the part where you pull data from your SavedInstanceState.

Daniel Ramirez
Daniel Ramirez
15,044 Points

If you want a quick fix (although I'm not sure this is the right fix), you can simply change the constructor for TodoAdapter to this:

public TodoAdapter(Activity activity, TodoList todoList) {
        inflater = LayoutInflater.from(activity);
        subscriber = todoList;
        data = todoList.getAll();
    }