Guest User

Untitled

a guest
Jan 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. MyAsyncTask task = new MyAsyncTask(this, country, img);
  2. task.execute();
  3.  
  4. SetSql mydb = new SetSql(this);
  5. mydb.open();
  6.  
  7. while(task.getStatus()!=AsyncTask.Status.FINISHED){
  8. //wait
  9. }
  10.  
  11. countryCode = mydb.getLatestCode();
  12. Log.e("debug", countryCode);
  13. mydb.close();
  14.  
  15. public class TaskTest extends AsyncTask<String, Integer, String> {
  16.  
  17. interface TaskDoneListener {
  18. abstract void onTaskDone(String result);
  19. }
  20.  
  21. private TaskDoneListener t;
  22.  
  23. public TaskTest(TaskDoneListener t){
  24. this.t = t;
  25. }
  26.  
  27. @Override
  28. protected String doInBackground(String... params) {
  29. // do your stuf
  30. return "some thing";
  31. }
  32.  
  33. @Override
  34. protected void onPostExecute(String result) {
  35. t.onTaskDone(result);
  36. super.onPostExecute(result);
  37. }
  38. }
  39.  
  40. countryCode = mydb.getLatestCode();
  41. Log.e("debug", countryCode);
  42. mydb.close();
  43.  
  44. public class TestActivity extends Activity implements TaskDoneListener {
  45. /** Called when the activity is first created. */
  46.  
  47. TaskTest task;
  48.  
  49.  
  50. @Override
  51. protected void onCreate(Bundle savedInstanceState) {
  52. super.onCreate(savedInstanceState);
  53. //create your layout and stuff
  54. }
  55.  
  56.  
  57. @Override
  58. protected void onStart() {
  59. super.onStart();
  60.  
  61. //Dont start you task in the onCreate this could cause some weird behavior
  62. //if the onCreate method is not yet done but your task is.
  63. task = new TaskTest((TaskDoneListener) this, ##country_code?##, ##image?##);
  64. task.execute();
  65. }
  66.  
  67.  
  68. public void onTaskDone(String result) {
  69. //set the results in your created views
  70.  
  71. }
  72.  
  73. }
Add Comment
Please, Sign In to add comment