该子类如何访问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(){}'


我已经尝试使用Abstract,但我无法使用它,因为它使应用程序崩溃,而且静态也不允许我对对象进行任何更改。



public static void updatePreferences


当“首选项活动”被销毁,测试并工作时被调用。现在,我只需要一种方法来找出在调用onDestroy时如何访问主要活动提要的子方法。

欧莉

最佳答案

好吧,简短的答案是:您不能。成为static或类级别方法的一部分意味着您不属于该类的任何特定实例。在没有为获取实例提供某种机制的情况下(也许通过将对实例的引用作为参数传递),您将不得不重新考虑自己的操作方式。

09-10 08:02
查看更多