kyle-erin
5/11/2015 - 8:25 PM

Example of Java AsyncTask

Example of Java AsyncTask

private class doSomethingInAnotherThread extends AsyncTask<Void, Void, Void>
  {
    @Override
    protected Void doInBackground( Void... params )
    {
      // Do the work here
      
      EventBus.getDefault().post(new CustomEvent(custom_data));
      return null;
    }

    @Override
    protected void onPostExecute( Void result )
    {
      // Executed on main thread
    }
  }
// in onCreate
EventBus.getDefault().register(this);

// in activity class somewhere
@SuppressWarnings( "UnusedDeclaration" )
public void onEventMainThread( CustomEvent event )
{
}