i am using a background service that it is retrieving data and inserting data on a remote server. OK, i puted it on a background service because i wanted to get that done in background without slowing down my app, but it is slowing down my app !
as you will see in the code, it haves a sleep of 60 seconds, and my app is getting frozen 2/3 seconds each 60 seconds, it is this code, i am sure, but i dont know how to solve it
public class MyService extends Service implements Runnable{
boolean serviceStopped;
RemoteConnection con; //conexion remota
List <Position> positions;
static SharedPreferences settings;
static SharedPreferences.Editor configEditor;
private Handler mHandler;
private Runnable updateRunnable = new Runnable() {
@Override public void run() {
//contenido
if (serviceStopped==false)
{
positions=con.RetrievePositions(settings.getString("login","")); //traigo todas las posiciones
if (positions.size()>=10) //si hay 10 borro la mas vieja
con.deletePosition(positions.get(0).getIdposition());
if (settings.getString("mylatitude", null)!=null && settings.getString("mylongitude", null)!=null)
con.insertPosition(settings.getString("mylatitude", null),settings.getString("mylongitude", null), formatDate(new Date()), settings.getString("login",""));
}
queueRunnable();//duerme
}
};
private void queueRunnable() {
//mHandler.postDelayed(updateRunnable, 60000); //envia una posicion al servidor cada minuto (60.000 milisegundos es un minuto)
mHandler.postDelayed(updateRunnable, 60000);
}
public void onCreate() {
serviceStopped=false;
settings = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
configEditor = settings.edit();
positions=new ArrayList<Position>();
con = new RemoteConnection();
mHandler = new Handler();
queueRunnable();
}