2012-08-05 4 views
0

여기 다른 사이트에서 다른 활동의 경고 대화 상자를 표시 할 수 없다는 내용의 충돌 보고서를 읽었습니다.Android가 다른 활동의 AlertDialog를 엽니 다.

public class Options extends Activity { 

    /** Include classes */ 
    SharedPreferences sharedPrefs; 
    Preferences prefs; 
    Location loc; 
    LocationSQL locSQL; 
    NetworkConnection netConnect; 

    /** Declare buttons */ 
    Button bLocation; 
    Button bRefresh; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.options); 

     sharedPrefs = PreferenceManager.getDefaultSharedPreferences(Options.this); 

     /** Set the location for the user */ 
     setLocationPref(); 

     /** Refresh selection */ 
     bRefresh = (Button) findViewById(R.id.bRefresh); 
     bRefresh.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
     loc = new Location(getApplicationContext()); 
      try{ 

       loc.locationSelection(); 
      }catch (Exception e){ 
       Log.d("ERROR", "Catch " + e); 
      } 
      } 
     }); 

     /** Location selection */ 
     bLocation = (Button) findViewById(R.id.bLocation); 
     bLocation.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 

      } 
     }); 
    } 
} 

내가 다음 몇 가지 처리를하고 싶지과 요구가있을 경우에 AlertDialog 상자를 호출 내가 이렇게 노력하고있어. 하지만 아래 오류가 발생합니다. 내가 옳다면 나는 파괴 된 상황을 사용하고 있다는 것을 이해한다. 그러나 나는 이것을 어떻게 풀어 낼지 생각할 수 없다.

public class Location { 

    private static final String Context = null; 
    NetworkConnection nc; 
    SharedPreferences getSharedPrefs; 
    SharedPreferences putSharedPrefs; 
    NetworkConnection netConnect; 
    Options opts; 
    Context context; 

    public Location (Context arg) 
    { 
     context = arg; 
    } 

    public void locationSelection(){ 

     message(); 

    } 

    public void message(){ 

     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); 
     alertDialogBuilder.setTitle("Your Title"); 
     AlertDialog alertDialog = alertDialogBuilder.create(); 
     alertDialog.show(); 

    } 

} 

캐치 android.view.WindowManager $ BadTokenException : 없음 창을 추가 - 토큰 널이 응용 프로그램이 아닙니다. 대신 YourClass.this을 전달하려고 당신의 위치 생성자에 getApplicationContext()를 통과

답변

0

(그래서 여기 Options.this) :-) 도와

많은 감사합니다.

또한이 코드 줄은 무엇입니까?

+0

감사합니다. 도움이 된 것 같습니다. 내가 시도한 것 같습니다./그 코드 줄은 복사하여 붙여 넣기 오류였습니다. 도움을 주셔서 감사합니다! – James

+0

확실한 것은 행복하게 작동했습니다! – DalvikDroid