安卓:写在AsyncTask的文件写在、文件、AsyncTask

由网友(冷堇°)分享简介:我希望能写在我的AsyncTask子类的本地目录,但我似乎无法弄清楚如何使用getFilesDir(),因为我不能,我的知识,创造ContextWrapper的一个实例,背景信息本子类。I would love to be able to write to a local directory in my AsyncT...

我希望能写在我的AsyncTask子类的本地目录,但我似乎无法弄清楚如何使用getFilesDir(),因为我不能,我的知识,创造ContextWrapper的一个实例,背景信息本子类。

I would love to be able to write to a local directory in my AsyncTask subclass, but I can't seem to figure out how to use getFilesDir(), since I cannot, to my knowledge, create an instance of ContextWrapper and Context in this subclass.

那么,你有什么我试过吗?我试图获取文件目录我知道如何通过尝试许多不同的东西,以便访问getFilesDir()方法创建上下文和ContextWrapper实例的唯一途径。而已。这就是我知道该怎么做。

So, what have I tried? I've tried getting the files directory the only way I know how by attempting many different things to create instances of Context and ContextWrapper in order to access the getFilesDir() method. That's it. That's all I know how to do.

我可能错过了很多公然明显的事情,但我一直在与Android现在的工作约2天,所以我还是不知道如何正确地调试我的问题。

I'm probably missing a lot of blatantly obvious things, but I've been working with Android for about 2 days now, so I still don't know how to debug my issues properly.

任何ExplainLikeImFive帮助是极大的AP preciated。

Any "ExplainLikeImFive" help is greatly appreciated.

编辑:

从我现在知道了,你只能通过活动获得的文件目录。这是为什么?

From what I know now, you can only get the files directory through an Activity. Why is that?

推荐答案

您需要使用上下文对象来访问文件在本地目录。您可以使用活动的实例作为你的上下文对象。创建一个的AsyncTask ,并把它送给你活动的参考。然后在你的的AsyncTask ,您可以使用活动来访问文件系统:

You need to use a Context object to access files in the local directory. You can use an instance of an Activity as your Context object. create an AsyncTask and give it a reference to your Activity. Then in your AsyncTask, you can use the Activity to access the filesystem:

activity.getFilesDir();
阅读全文

相关推荐

最新文章