gunar :
Both Service and Activity extend from ContextWrapper as well, so it has getFilesDir() method. Passing an instance of Service to AsyncTask object will solve it.\n\nSomething like:\n\nFile file = new File(myContextRef.getFilesDir() + \"/IP.txt\");\n\n\nWhen you're creating the AsyncTask pass a reference of current Service (I suppose you're creating the AsyncTaskObject from Service):\n\nimport java.io.File;\n\nimport android.app.Service;\nimport android.content.Intent;\nimport android.os.AsyncTask;\nimport android.os.IBinder;\n\npublic class MyService extends Service {\n @Override\n public IBinder onBind(Intent intent) {\n return null;\n }\n\n protected void useFileAsyncTask() {\n FileWorkerAsyncTask task = new FileWorkerAsyncTask(this);\n task.execute();\n }\n\n private static class FileWorkerAsyncTask extends AsyncTask<Void, Void, Void> {\n\n private Service myContextRef;\n\n public FileWorkerAsyncTask(Service myContextRef) {\n this.myContextRef = myContextRef;\n }\n\n @Override\n protected Void doInBackground(Void... params) {\n File file = new File(myContextRef.getFilesDir() + \"/IP.txt\");\n // use it ...\n return null;\n }\n }\n}\n",
2013-09-05T12:05:30