Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. JSONObject obj = new JSONObject(result);
  2. if (obj.getString("status").equals("success")) {
  3. JSONArray arr = obj.getJSONArray("response");
  4. UserNotificationTime jour;
  5. for (int i = 0; i < arr.length(); i++) {
  6. obj = arr.getJSONObject(i);
  7. jour = new UserNotificationTime();
  8. jour.set_breakfast_time(obj.getString("breakfast_time"));
  9. j_pref_bkTime = jour.get_breakfast_time();
  10. j_editor.putString("j_bktime", j_pref_bkTime);
  11. j_editor.commit();
  12. }
  13. } else {
  14. Toast.makeText(getApplicationContext(),
  15. obj.getString("response"), Toast.LENGTH_SHORT)
  16. .show();
  17. }
  18.  
  19. j_pref_bkTime = prefs.getString("j_bktime", "OFF"); // get json time from the shared preference
  20.  
  21.  
  22. int hours = new Time(System.currentTimeMillis()).getHours();
  23. int minute = new Time(System.currentTimeMillis()).getMinutes();
  24.  
  25. String time = hours + ":" + minute;
  26.  
  27. // splits json time (hour and minute to comapare with current time)
  28. StringTokenizer tokens_bk = new StringTokenizer(j_pref_bkTime,
  29. ":");
  30. String first_bk = tokens_bk.nextToken();
  31. String second_bk = tokens_bk.nextToken();
  32. String final_bktime = first_bk.trim() + ":" + second_bk.trim();
  33.  
  34. if (time.trim().equals(final_bktime.trim())) {
  35.  
  36. // perform some action here but it call when our app open and do some
  37. into this but i want to call this code also when application is
  38. close or open means how to compare this code-condition to call
  39. any time this body when current time match to json time.
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement