When you create an instance of class B make sure it takes Context as an argument in its constructor. Then you can try using AsyncTask (Assuming you know it). Then put the time consuming function in doInBackground() and the function which waits for its values in onPostExecute()