How to prevent custom views from losing state across screen orientation changes

I’ve successfully implemented onRetainNonConfigurationInstance() for my main Activity to save and restore certain critical components across screen orientation changes. But it seems, my custom views are being re-created from scratch when the orientation changes. This makes sense, although in my case it’s inconvenient because the custom view in question is an X/Y plot and the … Read more

How can you do anything useful without mutable state?

I’ve been reading a lot of stuff about functional programming lately, and I can understand most of it, but the one thing I just can’t wrap my head around is stateless coding. It seems to me that simplifying programming by removing mutable state is like “simplifying” a car by removing the dashboard: the finished product … Read more

React: how to update state.item[1] in state using setState?

I’m creating an app where the user can design his own form. E.g. specify name of the field and details of which other columns that should be included. The component is available as a JSFiddle here. My initial state looks like this: var DynamicForm = React.createClass({ getInitialState: function() { var items = {}; items[1] = … Read more

Updating an object with setState in React

Is it at all possible to update object’s properties with setState? Something like: this.state = { jasper: { name: ‘jasper’, age: 28 }, } I have tried: this.setState({jasper.name: ‘someOtherName’}); and this: this.setState({jasper: {name: ‘someothername’}}) The first results in a syntax error and the second just does nothing. Any ideas? 23 Answers 23

How to declare global variables in Android?

I am creating an application which requires login. I created the main and the login activity. In the main activity onCreate method I added the following condition: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); … loadSettings(); if(strSessionString == null) { login(); } … } The onActivityResult method which is executed when the login form terminates … Read more