2013-03-30 5 views
1

나는 myDataBsae 가치를 발견했을 때 통지 intentservice을 가지고 있지만 데이터가 그래서, 저를 통지하지 말아야 null의 경우Intentservice를 반복하는 방법은 무엇입니까?

  1. 어떻게 MYDATABASE 내 Intentservice 체크 내용이 매 50 초 (나는 알람 관리기를 사용 할 수 있습니다하지만 내 서비스 통지 내 데이터베이스 = null에도 불구하고 매 50 초마다)? 나는 그것이

내 서비스가 발사 할 때는

  • 나는, 내 intentservice 작업은 별도 스레드 원하는 :

    public class ShowTimeServer extends IntentService { 
    NotificationManager nm; 
    static final int uniqueID=326534; 
    public ShowTimeServer() { 
        super("ShowTimeServer"); 
        // TODO Auto-generated constructor stub 
    } 
    
    /* (non-Javadoc) 
    * @see android.app.IntentService#onHandleIntent(android.content.Intent) 
    */ 
    @Override 
    protected void onHandleIntent(Intent arg0) { 
        // TODO Auto-generated method stub 
    
        ShowTimeDB RetrieverDB =new ShowTimeDB(this); 
        RetrieverDB.open(); 
        String data = RetrieverDB.getShowNotify(); 
        RetrieverDB.close(); 
    
    
    
        if (!(data.equals(null))){ 
    
         nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
    
         Intent intent=new Intent(this,TodayShow.class); 
         PendingIntent pi= PendingIntent.getActivity(this, 0, intent, 0 ); 
         CharSequence x=(CharSequence) data; 
         Notification n=new Notification(R.drawable.ic_launcher,"YOU HAVE SHOW" ,System.currentTimeMillis()); 
         n.setLatestEventInfo(this, "ShowTime", x, pi); 
         n.defaults=Notification.DEFAULT_ALL; 
    
         nm.notify(uniqueID,n); 
         //pi.cancel(); 
         //nm.cancel(uniqueID); 
    
        } 
    } 
    
    } 
    
  • 답변

    0
    1. intentService가 가지마다 X 초를 어떻게해야되지 않습니다. 이를 위해 다른 많은 솔루션이 있습니다. 이 작업을 위해 서비스를 사용하기를 원한다면, 사용자가 앱을 나갔을 때 그것을하기를 원하는지에 따라 일반적인 전경/배경 서비스로 만들 수 있습니다.

    2. intentService는 이미 다른 스레드에서 실행됩니다. 이것이 onHandleIntent 메서드에서 오랜 작업을 수행 할 수있는 이유입니다.

    +0

    나는 runnable 또는 타이머를 만들 수 없다는 것을 의미 했습니까? –

    +0

    당신이 말하는 것을 이해하지 못합니다. 더 설명해주세요. 내 말은 –

    +0

    내가 아래에이 코드 사치 사용하고에 ***> 개인의 TimerTask mTask = 새로운 TimerTask를 내 알림 코드를 넣을 수 있습니다() { @Override 공공 무효 실행() { // 당신은 postDelayed 원하는대로 (this, REPEAT_INTERVAL); // 린스하고 반복하십시오 ... } }}; –

    관련 문제