该子类如何在动态壁纸服务中访问父类。
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
当首选项 Activity 被销毁、测试并工作时调用。现在我只需要一种方法来了解如何在调用 onDestroy 时访问主 Activity 提要的子方法。
奥利。
最佳答案
嗯,简短的回答是:你不能。作为静态
或类级方法的一部分意味着您不属于该类的任何特定实例。如果不为其提供某种获取实例的机制(也许通过将实例的引用作为参数传递),您将不得不重新考虑如何执行此操作。
关于java - 访问动态壁纸服务类中的子方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9153259/