【发布时间】:2012-11-10 12:39:29
【问题描述】:
在下面的代码 Eclipse 生成警告“这个处理程序类应该是静态的,否则可能会发生泄漏”。
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())!
【问题讨论】:
-
这和这个问题差不多:stackoverflow.com/questions/11407943/…
标签: java android memory-leaks