Problem in Context and SharedPreferences in android with service

4

I'm trying to create a service on android, it's ready though in running the application for. If I comment on the ctx and prefs variables, it works but I need them, can you tell me if there is something wrong that I did not see? I've been for a long time and I honestly do not find the problem. Here is the code

Note: Everything is already right in the manifest.

import java.sql.Timestamp;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import br.newm.alvomobile.database.EtapaPersistencia;
import br.newm.alvomobile.database.OSPersistencia;
import br.newm.alvomobile.webservice.OSWebService;
import br.newm.biblioteca.utils.AndroidUtils;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.util.Log;
public class DownloadManager extends Service implements Runnable{
   private Context ctx = getApplicationContext();
   private SharedPreferences prefs;
   private int id_usuario;
   private OSWebService oswebservice;
   private OSPersistencia ospersistencia;
   private String TAG = "DOWNLOAD-SERVICE";
}
    
asked by anonymous 15.08.2014 / 22:09

1 answer

4

Only removes varivable ctx and uses getApplicationContext() of the Service class where needed. Ex.:

public void test(){
     TextView textView = new TextView(getApplicationContext());
}
    
15.08.2014 / 22:13