Ta klasa Handler powinna być statyczna lub mogą wystąpić przecieki: final Handler
Na poniższym kodzie Eclipse generuje ostrzeżenie „Klasa Handler powinna być statyczna lub mogą wystąpić wycieki”.
public class MyActivity extends Activity implements Runnable
{
final Handler handler = new Handler()
{
@Override
public void handleMessage( Message message)
{
String sResult = (String) message.obj;
if( (sResult != null) && (sResult != ""))
{
MyNonStatic = (TableLayout) findViewById( R.id.tableLayout); // any non-static method
}
return;
}
};
public void run()
{
final Message message = handler.obtainMessage( 1, MyFunction( context));
handler.sendMessage( message);
}
public String MyFunction( Context context)
{
return "MyNewString";
}
}
Przeglądam wiele tematów na stronie, ale nie dostaję rozwiązania. Pomóż mi dla tego kodu?
Add: potrzebuję wywołać metodę niestatyczną (na przykład findViewById ()) w handleMessage ()!