Backing up user data in Note to Self
So, with our new-found 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 a JSONObject
and throws a JSONException
. The body of the constructor initializes ...
Get Android Programming for Beginners - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.