O'Reilly logo

Android Programming for Beginners by John Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Backing up user data in Note To Self

So, with our newfound insight into exceptions, let's modify our Note To Self code and then we can be introduced to JSONObject and JSONException.

First, let's make some minor modifications to our Note class. Add some more members that will act as the key in a key-value pair for each aspect of our Note class:

private static final String JSON_TITLE = "title";
private static final String JSON_DESCRIPTION = "description";
private static final String JSON_IDEA = "idea" ;
private static final String JSON_TODO = "todo";
private static final String JSON_IMPORTANT = "important";

Now, add a constructor and empty default constructor that receives JSONObject and throws JSONException. The body of the constructor initializes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required