I can't use the getFilesDir() in an asynctask which is in a service. I saw this post: Android: Writing to a file in AsyncTask It solves the problem in an activity but i dont find a way to do this in a service. How to write to an internal storage file with an asynctask in a service? This is my code in the asynctask:
File file = new File(getFilesDir() + "/IP.txt");
Both
Service
andActivity
extend fromContextWrapper
as well, so it hasgetFilesDir()
method. Passing an instance of Service toAsyncTask
object will solve it.Something like:
When you're creating the AsyncTask pass a reference of current Service (I suppose you're creating the
AsyncTaskObject
from Service):I think when you start your service, you should pass String path which
getFileDir()
provides as follow.In your service in
onStart
method,