DEV Community

Dimitrios Desyllas
Dimitrios Desyllas

Posted on


How I can update the Activity's UI using lambdas for events?

As I ask upon:

I have a class that I provide callbacks via lambdas. These lambdas provide callback functionality and update the Activity's UI.

In a nutshell I have the following class:

class MyProcess extends Runnable{

   Callback callback;
   Callback exceptionCallback;   

   public function setCallback(Callback callback){this.callback=callback;}

   public function setExceptionCallback(Callback callback){this.exceptionCallback = callback}

   public void doStuff()
        // Some Logic there that performs Networking;
      }catch(Exception e){; }

   public void run(){ this.doStuff(); }
Enter fullscreen mode Exit fullscreen mode

And in my activity I do the following

 class MyActivity extends extends AppCompatActivity implements View.OnClickListener{
   MyProcess process;
   protected void onCreate(Bundle savedInstanceState) {
       process = new MyProcess();
       process.setExceptionCallback((Exception e)->{                Log.e("MyApp",MyActivity.class+e.getMessage());
       Button submit = (Button)findViewById(;
  public void onClick(View v){

        Button submit = (Button)findViewById(;

Enter fullscreen mode Exit fullscreen mode

But the runOnUiThread does not allow me to perform networking. Therefore, do you have any Idea how I can run a thread that performs networking;

Top comments (0)