2014-09-29 3 views
0

내 응용 프로그램에서 정기적으로 업데이트되는 연락처 목록, 그룹 목록 및 서버에서 업데이트 된 폴더 목록이 필요합니다. 지금은 저장 환경 설정에 저장하고 있습니다. 현재 필요한 각 유형의 목록이있는 경우 로그인시 업데이트를 건너 뛰고 로그인 후에이 데이터를 업데이트하는 백그라운드 asyncTask를 호출하는 메소드를 구현했습니다. 문제는 사용자가 로그인 할 수있는 연결이 낮지 만 아무 것도 할 수 없으며 다른 사용자가 요청한 블록을 백그라운드에서 기다리는 것을 기다리는 것입니다. 이 데이터를 주기적으로 새로 고침하려면 어떻게해야합니까? 앱이 활성화되지 않은 경우에도 데이터를 업데이트하는 서비스처럼백그라운드에서 데이터 업데이트

+0

코드를 게시하십시오. –

답변

0

아마 Service을 사용해야합니다.

public class MyService extends Service { 

@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
    //TODO do something useful 
    return Service.START_NOT_STICKY; 
} 

@Override 
public IBinder onBind(Intent intent) { 
    //TODO for communication return IBinder implementation 
    return null; 
} 
} 

시작 서비스

Android Service Tutorial

manifest.xml

<service 
    android:name="MyService" 
    android:icon="@drawable/icon" 
    android:label="@string/service_name"> 
</service> 

MyService.java

// use this to start and trigger a service 
Intent i= new Intent(context, MyService.class); 
// potentially add data to the intent 
i.putExtra("KEY1", "Value to be used by the service"); 
context.startService(i); 
+0

앱의 요청없이 장치 배경에서 주기적으로 실행할 수 있습니까? – fustalol

+0

예, 서비스는 백그라운드에서 실행됩니다. – R9J

관련 문제