I tried to use AsyncTask but is deprecated and i dont understand how to use Executors can someone help me how can use it with just small example
my code below
public void onClick(View view) {
String obj = this.txtone.getText().toString();
String obj2 = this.txttwo.getText().toString();
String obj3 = this.txttime.getText().toString();
Double value2 = Double.valueOf(obj);
Double value3 = Double.valueOf(obj2);
Double value4 = Double.valueOf(obj3);
Double valueOf = value4;
this.table.removeAllViews();
NumberFormat instance = NumberFormat.getInstance(Locale.US);
String[] strArr = {"Times " , "number 1","number 1" ,"Sum"};
addTableRowHeader(strArr[0], strArr[1], strArr[2], strArr[3]);
String str = "";
int i = 0;
while (((double) i) < valueOf.doubleValue()) {
double sum = value2 + value3;
StringBuilder stringBuilder;
stringBuilder = new StringBuilder(str);
i++;
stringBuilder.append(i);
addTableRow(stringBuilder.toString(), instance.format(value2), instance.format(value3), instance.format(sum));
valueOf2 = sum;
}
2
Answers
You can use Executors:
For Multi Threading :
For Single Thread :
Now simply execute your work using execute() function like this :
Just remember to shutdown the Executor when you are finished like this :
This can also be used