2012-10-22 5 views
0

GPS 위치를 기록하는 활동이있는 애플리케이션을 개발 중입니다. LocationListener 업데이트를 등록하고 기록 된 위치를 SQLite 데이터베이스에 저장합니다. 내 문제는 사용자가 내 앱을 숨기거나 다른 앱을 실행할 때 내 앱과 녹화 활동이 백그라운드로 이동하여 시스템에 의해 종료 될 수 있다는 것입니다. 따라서 GPS 데이터는 저장되지 않습니다. 앱이 백그라운드로 이동하더라도 내 앱 및 녹화 활동이 GPS 위치를 기록하고 싶습니다. 어떻게 달성할까요? 어떤 GUI없이 백그라운드에서 실행 할 수 BroadcastReceiver 또는 Service 같은 안드로이드의백그라운드에서 GPS를 기록하는 Android 활동

감사

+1

서비스를 시작합니다. – 13hsoj

답변

0

를 사용하여 다른 구성 요소. 서비스의 경우

public class UploadData extends BroadcastReceiver 
{ 
    private static LocationManager locationManager = null; 
    private static LocationListener locationListener = null; 

     @Override 
    public void onReceive(Context context, Intent intent) 
    { 
      // Create and AlarmManager that will periodically fetch the GPS 
    } 
} 

,

public class myservice extends Service 
{ 
    LocationManager locationManager = null; 
    LocationListener loclistener = null; 

     // Bind it, Its important 
    public IBinder onBind(Intent intent) 
    { 
     return null; 
    } 
    @Override 
    public void onCreate() 
    { 
      // Use AlarmManager to fetch the GPS periodically. 
    } 
} 
2

Service는 당신이하고자하는 것에 대해 최고입니다.

만들기 슈어 당신은 당신이 대신 활동의 서비스 내에서 위치를 가져 오도록 코드를 작성할 수 있습니다 STICKY

관련 문제