how to receive value from object launched in new Thread in java

  android, class, java, methods, multithreading

I have a problem when I want to receive result using other class.

Let’s say I have two methods in my class "NewImage" : fct_1() and fct_2()

fct_2() is launched in a new Thread and fct_1() doesnt.

so in my new other class where I want to show the result:

this one works fine :

Bitmap received=null;
final NewImage NewImage_1 = new NewImage ();
received = NewImage_1.fct_1();

and this doesnt

Bitmap received=null;
final NewImage NewImage_1 = new NewImage ();
received = NewImage_1.fct_2();

My Methods are :

public static Bitmap fct_1()
{
code 1
}

public static Bitmap fct_2()
{
new Thread(new Runnable() {public void run(){
code 2
}});
}

Is there a way to fix this please?

Source: Android Questions

LEAVE A COMMENT