title: How to make a new thread, Android Studio?
body: <p>I have the following fragment class:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class fragment1 extends Fragment {
      private TextView bunz_count;
      private TextView money_count;
      private Bunz bunz;
      private Handler handler;
      int delay = 1000;
      View view;
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          bunz = Bunz.getInstance();
          handler = new Handler();
  
  
          view = inflater.inflate(R.layout.fragment1, container, false);
  
  
          handler.postDelayed(new Runnable(){
              public void run(){
                  update(view);
                  handler.postDelayed(this, delay);
              }
          }, delay);
  
  
  
  
  
  
  
          return view;
      }
  
  
      public void update(View view){
          bunz_count = (TextView) view.findViewById(R.id.final_bunz_count);
          money_count = (TextView) view.findViewById(R.id.final_money_count);
          //System.out.println(bunz.getBaker1());
  
  
          BigDecimal number = ((BigDecimal.valueOf
                  (bunz.getBaker1()).multiply(BigDecimal.valueOf(.1))));
  //        ).add((BigDecimal.valueOf(bunz.getBaker2()).multiply(BigDecimal.valueOf(.2)))).
  //                add((BigDecimal.valueOf
  //                        (bunz.getBaker3()).multiply(BigDecimal.valueOf(.4)))).
  //                add((BigDecimal.valueOf
  //                        (bunz.getBaker4()).multiply(BigDecimal.valueOf(.8)))).
  //                add((BigDecimal.valueOf(bunz.getBaker5()).multiply(BigDecimal.valueOf(1)))).
  //                add((BigDecimal.valueOf(bunz.getBaker6()).multiply(BigDecimal.valueOf(2)))).
  //                add((BigDecimal.valueOf(bunz.getBaker7()).multiply(BigDecimal.valueOf(4)))).
  //                add((BigDecimal.valueOf(bunz.getBaker8()).multiply(BigDecimal.valueOf(5)))).
                  //add((BigDecimal.valueOf(bunz.getBaker9()).multiply(BigDecimal.valueOf(10))));
          //System.out.println(number);
          bunz.setBunz(bunz.getBunz().add((number)));
          bunz_count.setText("Bunz: " + bunz.getBunz());
          money_count.setText("Money: " + bunz.getMoney());
          System.out.println("bunz" + bunz.getBunz());
  
      }
  }
  </code></pre>
  
  <p>which updates the UI display of a players currency. However, since there are lots of different processes running in the background, this thread lags and has problems. How can I run this on a separate thread to avoid this?</p>
  
  <p>Edit: I tried something like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>        mHandlerThread = new HandlerThread("yeye");
          mHandlerThread.start();
          handler = new Handler(mHandlerThread.getLooper());
          handler.postDelayed(new Runnable(){
              public void run(){
                  update(view);
                  handler.postDelayed(this, delay);
              }
          }, delay);
  </code></pre>
  
  <p>but it didn't help!</p>
  
  <p>Thanks!</p>