在下面的代码中,Eclipse会生成警告"This Handler class should be static or leaks might occur"。
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";
}
}
我在网站上查看了很多主题,但是没有得到解决方案。请帮我解决这个问题吧!
补充一下:我需要在handleMessage()方法中调用非静态方法(例如findViewById())!