2012-02-05 53 views
0

此子類如何訪問Livewallpaper服務中的父類。Livewallpaper服務類中的訪問子方法

public class LiveWallpaperService extends WallpaperService 
{ 
public static final String SHARED_PREFS_NAME="t_settings"; 
public static final String strSharedPrefs="t_settings"; 

@Override 
public Engine onCreateEngine() 
{  
    return new LiveWallpaperWallpaperEngine(); 
} 

public static void updatePreferences() 
{ 
    //This is the class that needs to access the child method. 
    Log.w("yo", "resumed from main activity"); 
} 

    public class LiveWallpaperWallpaperEngine extends Engine implements SharedPreferences.OnSharedPreferenceChangeListener 
    { 
     //This is the child method I'm trying to access. 
     public void updatePreferencesB(){}' 

我使用抽象,我不能,因爲它的應用程序崩潰也靜態不允許我做出對象的任何更改嘗試。

public static void updatePreferences 

是當首活性被破壞,測試和工程調用。現在我只需要一種方法來找出如何在調用onDestroy時訪問主要活動源的子方法。

Olly。

+0

你似乎已經實現了''OnSharedPreferenceChangeListener'',我不禁想知道你需要這個靜態''updatePreferences''嗎? – harism 2012-02-05 21:46:51

回答

1

好吧,簡短的回答是:你不能。作爲static或類級別方法的一部分意味着您不屬於該類的任何特定實例。如果沒有提供獲取實例的某種機制 - 也許通過將實例的引用作爲參數傳遞給您 - 您將不得不重新考慮如何執行它。

+0

感謝您的提示! – 2012-02-05 21:52:07

+0

最受歡迎,祝你好運。 – 2012-02-05 21:56:22