2011-08-01 9 views
0

AsyncTask를 확장하는 클래스가 있습니다.클래스에서 SendBroadcast AsyncTask를 확장 할 수 있습니까?

하는 배경 작업이 완료되면, 게시물에 내가 배경을하고 결과를 동일하게 다른 클래스의 정적 속성을 얻을 실행, n은 그래서 다른 클래스의에 수신기가 갱신 인터페이스

될 것이라고 IT를 OUT 방송 싶지 여기

제가 sendBroadcast 방법을 쓸 수 후 onPostExecuted

protected void onPostExecute(String result) { 
    Log.d(tag, "post executed "+result); 
    // do sth here 

    if (result != null){ 
     result = result.trim(); 
     String temp_result[]; 
     if (result.contains("|")){ 
      temp_result = result.split("\\|"); 
      MyGPS.location_info = temp_result[1];// 
      Log.d(result, "contains | : "+MyGPS.location_info); 
     }else if (result.equalsIgnoreCase("300 OK")){ 
      Log.d(result, "in 300 OK BUT UNKNOWN : "+ result); 
      MyGPS.location_info = "Unknown"; 
     }else if (result.equalsIgnoreCase("400 ERROR")) 
      Log.d(result, "400 ERROR : "+ result); 
     else Log.d(result, "else : "+ result); 

     //assemble data bundle to be broadcasted 
     //myFilteredResponseThread = new Intent(GPS_FILTER); 
     myFilteredResponseThread.putExtra("location_info_post", 

MyGPS.location_info); 
        // CAN"T USE SEND BROADCAST METHOD ? 


     //myFilteredResponseThread. 
     //Log.e(">>GPS_Service<<", "location_info"+MyGPS.location_info); 
    } 
} 

의 코드, 그 이유는 정의되지?

+0

은 AsyncTask를 확장이 클래스에 활동 상황을 전달하지 않습니다 수 있습니다. 당신이 활동 컨텍스트를 전달하는 경우 context.sendbroadcat (intent) – Vivek

+0

을 사용합니다. 내 내부 GPSListener에서이 스레드 AysnctTask를 호출하여 LocationListener를 구현하고이 내부 클래스가 클래스 확장 서비스에 있으므로 내 AsyncTask에 컨텍스트를 전달할 수 있습니까? thx – sayvortana

답변

0

내가 올바르게 이해하면 다음과 같은 해결책입니다.

class MyService extends Service{ 

    @Override 
    public IBinder onBind(Intent arg0) { 
     // TODO Auto-generated method stub 
     return null; 
    } 

     class GPSListener implements LocationListener{ 
     public void onLocationChanged(Location arg0) { 
      // TODO Auto-generated method stub 
        // you can get context as follow 
      MyService.this.getBaseContext().sendBroadcast(new Intent("Hi")); 
     } 

     public void onProviderDisabled(String arg0) { 
      // TODO Auto-generated method stub 

     } 

     public void onProviderEnabled(String arg0) { 
      // TODO Auto-generated method stub 

     } 

     public void onStatusChanged(String arg0, int arg1, Bundle arg2) { 
      // TODO Auto-generated method stub 

     } 

    } 

     } 

}

+0

Thx boy, 나는 MyService.this.getBaseContext(). sendBroadcast (새로운 의도 ("안녕하세요)") 이후로 혼란 스럽습니다. 여기에 새로운 의도 ("안녕하세요") 사촌 난 1 2 내 AsyncTask 클래스에 문맥을 보내, 미안 해요 이후 나는 초보자이다 – sayvortana

+0

u는 어떻게 호출 스레드를 호출 할 수 있습니다 AysnctTask – Vivek

관련 문제