android studio“this”参数错误的后台工作者

时间:2017-07-31 23:28:48

标签: android server backgroundworker

初始化我的后台工作者我使用此代码。 BackgroundWorker是一个类。 出于某种原因,“this”表示“无法应用”。

git pull --no-edit

===来自该地区的更多代码===

BackgroundWorker backgroundWorker = new BackgroundWorker(this);

===工人===

https://pastebin.com/rMZqvvhF

上面的代码是持有BackgroundWorker的类。在这堂课上。它连接并添加或登录到服务器。我很新,所以我很感激帮助。

=========编辑(额外帮助)=========

谢谢大家的帮助,但我有一个问题。当我将其更改为getApplicationData时,它会运行后台工作程序,但随后会崩溃应用程序。任何想法?

========= EDIT ======

看起来你的Backgroundworker在构造函数中使用了Context。不要使用“this”,而是尝试使用getApplicationContext()来获取上下文。

2 个答案:

答案 0 :(得分:0)

因为您的示例中的.png会引用this而不是OAuthAuthenticationListener。所以使用类似的东西:

Activity

如果您的代码位于BackgroundWorker backgroundWorker = new BackgroundWorker(getBaseContext()); 内,请改用Fragment

答案 1 :(得分:0)

看起来你的Backgroundworker在构造函数中使用了Context。不要使用“this”,而是尝试使用getApplicationContext()来获取上下文。