title: How do i connect my main thread with a created worker thread?
body: <p>Hey I have a trouble with using a room database on android studio java. 
  I am trying to save the components of a class when I click on a save button. 
  but the thing is that it is a bad thing to use a save or download call on a main thread so I am creating my own thread but how do I then outside of that thread use the data? my class that I'm doing this in looks like this...</p>
  
  <p>UPDATE: Should this work then? </p>
  
  <pre><code>package com.example.jenso.paperseller;
  
  import android.arch.persistence.room.Room;
  import android.content.Intent;
  import android.os.Bundle;
  import android.os.PersistableBundle;
  import android.support.annotation.Nullable;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  
  public class CreateCustomer extends AppCompatActivity {
      EditText name;
      EditText address;
      EditText phonenumber;
      EditText email;
      Button saveCustomer;
      PapperSellerDatabase pd;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.create_customer);
          name = findViewById(R.id.nameInput);
          address = findViewById(R.id.addressInput);
          phonenumber = findViewById(R.id.phonenumberInput);
          email = findViewById(R.id.emailInput);
          saveCustomer = findViewById(R.id.saveInput);
          setTheDataBase();
  
  
          saveCustomer.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  startActivity(new Intent(CreateCustomer.this, MainActivity.class));
                  pd.customerDao().insertAll(new Customer(name.getText().toString(),address.getText().toString(),phonenumber.getText().toString(),email.getText().toString()));
              }
          });
  
  
  
  
      }
      public void setTheDataBase(){
          new Thread(new Runnable() {
              @Override
              public void run() {
                  //here you obtain data from async source
                  PapperSellerDatabase pd = Room.databaseBuilder(getApplicationContext(),PapperSellerDatabase.class,"production")
                          .fallbackToDestructiveMigration()
                          .build();
  
  
              }
          }).start();
  
  
  
      }
  }
  </code></pre>
  
  <p>and on the load side I do this?</p>
  
  <pre><code>package com.example.jenso.paperseller;
  
  import android.arch.persistence.room.Room;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.support.v7.widget.ThemedSpinnerAdapter;
  import android.support.v7.widget.Toolbar;
  import android.util.Log;
  import android.view.View;
  import android.view.Menu;
  import android.view.MenuItem;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity {
      RecyclerView recyclerView;
      RecyclerView.Adapter adapter;
      List&lt;Customer&gt; customers;
      PapperSellerDatabase database;
  
  
      FloatingActionButton fab;
      private static final  String TAG = "MainActivity";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          recyclerView = findViewById(R.id.recycler);
          customers = new ArrayList&lt;&gt;();
  
  
          recyclerView.setLayoutManager(new LinearLayoutManager(this));
          adapter = new PapperRecyclerAdapter(customers,this);
          recyclerView.setAdapter(adapter);
  
          downloadTheData();
  
          fab = findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Log.d(TAG, "onClick: Do this when you click");
                  startActivity(new Intent(MainActivity.this, CreateCustomer.class));
              }
  
          });
  
  
  
      }
      private void downloadTheData(){
          new Thread(new Runnable() {
              @Override
              public void run() {
                  //here you obtain data from async source
                  PapperSellerDatabase pd = Room.databaseBuilder(getApplicationContext(),PapperSellerDatabase.class,"production")
                          .fallbackToDestructiveMigration()
                          .build();
  
  
                  customers = pd.customerDao().getAllCustomers();
  
              }
          }).start();
  
  
  
  
      }
  
  
  
  
  }
  </code></pre>
  
  <p>so how would I go further with if I click the button I wanna save the data to the room database and then leave the view? </p>