I am using a handler
object to continue UI work after finished a time consuming task in a seperate thread. Had a problem of the above Lint warning and following was my approach.
[ Sample Handler object type 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();
}
};
[ Sample Handler object type 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; // RETURN VALUE ????
}
});
In the seperate thread(other than UI) when the time consuming task is done, it executes the following line to get the control back to UI thread(basically to the handler obj).
responseHandler.sendEmptyMessage(0);
The program works really fine with both types of handler objects, but with 1st type I am getting a Lint warning saying This Handler class should be static or leaks might occur.
Therefore I started using the 2nd type of handler object to avoid the Lint warning but the problem I've got is, I am not sure about the meaning of return value (true/false) in the 2nd way and also it works with either. I searched for this in google for so much but didn't get an exact answer explained this return value.
Yes, I saw this question had asked in many places in stackoverflow mainly reagrding the Lint warning, but my question is mainly about the return type in the 2nd way and to get it confirm if it's alright the way I solve the issue using the 2nd type of handler Obj.
Questions ->
1). Does anybody know what exacly this return value means(true/false) ?
2). Is it the correct thing I have done to get rid of the lint warning?
Thanks...