是否可以在 Activity 的下一个生命周期中重用之前在其上一个会话中创建的 Handler 对象(在 onPause、onDestroy() 之前)?
就像我在 Activity 中创建一个 Handler 将其传播到其他地方的其他对象一样,Activity 死掉或暂停,然后再次复活并使用旧的处理程序?
// In the oncreate() method I have this code to recreate handler every time
// Then I set the handler to a static Global object
// Other Objects use the global object's static method to get
//fresh handler every timebefore calling sendMessage()
/**
* Set up handler
*/
Handler h = new Handler(new Callback()
{
public boolean handleMessage(Message msg)
{
handleServiceMessage(msg);
return true;
}
});
uiglobal = new UIGlobals(h);
UiGlobals 被声明为
private static UIGlobals uiglobal = null;
不确定上述方法是否正确..
我的 GlobalUI 类看起来像这样
public class UIGlobals
{
private static Handler handler = null;
public UIGlobals(Handler h)
{
handler = h;
}
public static Handler getHandler()
{
return handler;
}
}