2012-02-05 8 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가 호출 될 때 주요 활동 피드의 하위 메소드에 액세스하는 방법을 찾는 방법이 필요합니다.

올리.

+0

''OnSharedPreferenceChangeListener''를 이미 구현 한 것 같아요.이 정적 인''updatePreferences''가 필요한 것에 궁금해 할 수 없습니까? – harism

답변

1

글쎄, 짧은 대답은 : 당신은 할 수 없습니다. static 또는 클래스 수준 메서드의 일부는 클래스의 특정 인스턴스에 속하지 않음을 의미합니다. 매개 변수로 인스턴스에 대한 참조를 전달하여 인스턴스를 획득하기위한 메커니즘을 제공하지 않으면 어떻게 수행하는지 다시 생각해야합니다.

+0

팁 주셔서 감사! –

+0

대환영, 행운을 빈다. –

관련 문제