I use the handler object to continue working with the user interface after completing the multitask task in a separate thread. Had the problem of Lint's aforementioned warning and the next been my approach.
[Handler object type of example 1] →
Handler responseHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); Toast.makeText(MainActivity.this, "Finished the long running task in seperate thread...", Toast.LENGTH_LONG).show(); } };
[Type of sample handler object 2] →
Handler responseHandler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { Toast.makeText(MainActivity.this, "Finished long running task in a seperate thread...", Toast.LENGTH_LONG).show(); return false;
In a separate thread (except for the user interface), when a laborious task is performed, it executes the following line to return control to the user interface thread (mainly for the obj handler).
responseHandler.sendEmptyMessage(0);
The program works fine with both types of handler objects, but with the 1st type I get a Lint warning saying . This handler class must be static or a leak may occur .
Therefore, I started using a type 2 handler object to avoid the Lint warning, but the problem I received is not sure about the value of the return value (true / false) in the 2nd way, and it also works with them. I searched this on google so much, but did not get an exact answer, explained this return value.
Yes, I saw that in many places this question was asked on stackoverflow, mainly overflowing the Lint warning, but my question mainly concerns the type of return in the second method and for confirming whether this is good, how I solve the problem using the 2nd handler type Obj.
Questions →
1). Does anyone know what this means that the return value means (true / false)?
2). Did I do it right to get rid of the pile warning?
Thanks...