2013-06-04 64 views
4

我有問題如何在服務中調用我的方法,我的方法是getambil_jmlgangguan()如何從其他活動中調用服務方法

詳細的代碼是在這裏:

public class GetCountDataGangguanService extends Service { 

    public String JUMLAH_GANGGUAN =""; 
    public static final String TAG = "MyServiceTag1"; 

    GlobalKoneksi konek_url = new GlobalKoneksi(); 
    GetJmlGangguanFunction jmlGangguanFUnctions = new GetJmlGangguanFunction(); 

    private static String KEY_SUCCESS = "success"; 
    private static String KEY_JUMLAH_DATA = "jumlah"; 
    JSONArray jml_data_json = null; 

    // UserFunctions userFunctions; 
    UserFunctions userFunctions = new UserFunctions(); 
    SessionManager session; 

    @Override 
    public void onCreate() { 
     // TODO Auto-generated method stub 
     mHandlers = new ArrayList<Handler>(); 

     Toast.makeText(this, "GetCountDataGangguan.onCreate()", 
       Toast.LENGTH_SHORT).show(); 
     //getambil_jmlgangguan(); 
    } 

    @Override 
    public IBinder onBind(Intent intent) { 
     // TODO Auto-generated method stub 
     Toast.makeText(this, "GetCountDataGangguan.onBind()", Toast.LENGTH_SHORT) 
       .show(); 
     return messenger.getBinder(); 

    } 

    public class LocalBinder extends Binder { 
     public GetCountDataGangguanService getServerInstance() { 
      return GetCountDataGangguanService.this; 
     } 
    } 

    @Override 
    public void onDestroy() { 
     // TODO Auto-generated method stub 

     Log.d("GetCountDataGangguan.onDestroy()", "Sudah di destroy"); 
     Toast.makeText(this, "GetCountDataGangguan.onDestroy()", 
       Toast.LENGTH_SHORT).show(); 

     super.onDestroy();   

    } 

    @Override 
    public void onStart(Intent intent, int startId) { 
     // TODO Auto-generated method stub 
     super.onStart(intent, startId); 

    } 

    @Override 
    public boolean onUnbind(Intent intent) { 
     // TODO Auto-generated method stub 
     Toast.makeText(this, "GetCountDataGangguan.onUnbind()", 
       Toast.LENGTH_SHORT).show(); 
     return super.onUnbind(intent); 
    } 


    public String getambil_jmlgangguan(){ 

     session = new SessionManager(getApplicationContext()); 
     session.checkLogin(); 
     HashMap<String, String> user = session.getUserDetails(); 
     String unit_id = user.get(SessionManager.KEY_UNITID); 
     String regu_id = user.get(SessionManager.KEY_REGUID); 

     JSONObject jsondatagangguan = jmlGangguanFUnctions.getcountdata(
       regu_id, unit_id); 

     try { 
      Log.d("JUMLAH_GANGGUAN",jsondatagangguan.getString(KEY_JUMLAH_DATA)); 
       JUMLAH_GANGGUAN = jsondatagangguan.getString(KEY_JUMLAH_DATA); 

     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 

     return JUMLAH_GANGGUAN; 


    } 

} 

如何調用方法getambil_jmlgangguan()另一活動e.g MainActivity並定期獲得JUMLAH_GANGGUAN結果。

回答

相關問題