Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

#Threads

Threads

Your application seem to be both using Thread and AsyncTask. For Android, I'd recommend using AsyncTasks and/or ExecutorServices. That is, avoid using Thread directly. This is just my opinion though.


#JSON

JSON

This code looks (削除) bananas (削除ここまで) bad:

map.put(TAG_FIRSTNAME, jb.getString(TAG_FIRSTNAME));
map.put(TAG_MIDDLENAME, jb.getString(TAG_MIDDLENAME));
map.put(TAG_LASTNAME, jb.getString(TAG_LASTNAME));
map.put(TAG_EMAIL, jb.getString(TAG_EMAIL));
(...)

One step to clean it up would be to use a String array of all the values you want, and then loop through that array.

String[] keys = { TAG_FIRSTNAME, TAG_MIDDLENAME, TAG_LASTNAME, TAG_EMAIL };
for (String key : keys) {
 map.put(key, jb.getString(key));
}

However, an even better way to do it would be to use the Jackson library which can parse the JSON into a Java object. I can highly recommend this library, I have used it in multiple projects (also for an Android application) and it works great! Take a look at Jackson in five minutes to understand the basics of using that library.

#Threads

Your application seem to be both using Thread and AsyncTask. For Android, I'd recommend using AsyncTasks and/or ExecutorServices. That is, avoid using Thread directly. This is just my opinion though.


#JSON

This code looks (削除) bananas (削除ここまで) bad:

map.put(TAG_FIRSTNAME, jb.getString(TAG_FIRSTNAME));
map.put(TAG_MIDDLENAME, jb.getString(TAG_MIDDLENAME));
map.put(TAG_LASTNAME, jb.getString(TAG_LASTNAME));
map.put(TAG_EMAIL, jb.getString(TAG_EMAIL));
(...)

One step to clean it up would be to use a String array of all the values you want, and then loop through that array.

String[] keys = { TAG_FIRSTNAME, TAG_MIDDLENAME, TAG_LASTNAME, TAG_EMAIL };
for (String key : keys) {
 map.put(key, jb.getString(key));
}

However, an even better way to do it would be to use the Jackson library which can parse the JSON into a Java object. I can highly recommend this library, I have used it in multiple projects (also for an Android application) and it works great! Take a look at Jackson in five minutes to understand the basics of using that library.

Threads

Your application seem to be both using Thread and AsyncTask. For Android, I'd recommend using AsyncTasks and/or ExecutorServices. That is, avoid using Thread directly. This is just my opinion though.


JSON

This code looks (削除) bananas (削除ここまで) bad:

map.put(TAG_FIRSTNAME, jb.getString(TAG_FIRSTNAME));
map.put(TAG_MIDDLENAME, jb.getString(TAG_MIDDLENAME));
map.put(TAG_LASTNAME, jb.getString(TAG_LASTNAME));
map.put(TAG_EMAIL, jb.getString(TAG_EMAIL));
(...)

One step to clean it up would be to use a String array of all the values you want, and then loop through that array.

String[] keys = { TAG_FIRSTNAME, TAG_MIDDLENAME, TAG_LASTNAME, TAG_EMAIL };
for (String key : keys) {
 map.put(key, jb.getString(key));
}

However, an even better way to do it would be to use the Jackson library which can parse the JSON into a Java object. I can highly recommend this library, I have used it in multiple projects (also for an Android application) and it works great! Take a look at Jackson in five minutes to understand the basics of using that library.

Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 157
  • 311

#Threads

Your application seem to be both using Thread and AsyncTask. For Android, I'd recommend using AsyncTasks and/or ExecutorServices. That is, avoid using Thread directly. This is just my opinion though.


#JSON

This code looks (削除) bananas (削除ここまで) bad:

map.put(TAG_FIRSTNAME, jb.getString(TAG_FIRSTNAME));
map.put(TAG_MIDDLENAME, jb.getString(TAG_MIDDLENAME));
map.put(TAG_LASTNAME, jb.getString(TAG_LASTNAME));
map.put(TAG_EMAIL, jb.getString(TAG_EMAIL));
(...)

One step to clean it up would be to use a String array of all the values you want, and then loop through that array.

String[] keys = { TAG_FIRSTNAME, TAG_MIDDLENAME, TAG_LASTNAME, TAG_EMAIL };
for (String key : keys) {
 map.put(key, jb.getString(key));
}

However, an even better way to do it would be to use the Jackson library which can parse the JSON into a Java object. I can highly recommend this library, I have used it in multiple projects (also for an Android application) and it works great! Take a look at Jackson in five minutes to understand the basics of using that library.

lang-java

AltStyle によって変換されたページ (->オリジナル) /