在之前的會話中(在onPause,onDestroy()之前)創建的Activity的下一次生命中重用Handler對象是否可以?在onDestroy()onPause()之前創建的Activity中使用先前的Handler是否可以?
就像我在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;
}
}
一般來說,只要舊的處理程序不保留舊的活動(通過掛起的回調等)。代碼示例可能允許更具體的響應。 – Devunwired
我已經更新了這個問題,請看看。謝謝 – Ahmed