我在变量中有上下文,我如何知道上下文是否是intentService?
public void syncToServer(Context context){
if ( is intentService ){
hpptClientSend();
}else{
hpptClientAsyncSend();
}
}
问题是当我想在使用httpclient的intentservice AsyncTask中使用时,因为android不允许在服务中使用并行线程: An asyncTask launched from an onPostExecute of another AsyncTask does not execute properly in API 10
我需要在 IntentService 中使用 httpClient,但与我在 UI 线程中使用的函数相同,并且需要 AsynkTask。
最佳答案
在 Java 中,使用 instanceof
运算符来确定对象是否是某个类或接口(interface)的实例。因此,如果 context
是 IntentService
的实例(或 IntentService
的某个子类),context instanceof IntentService
将为 true
,否则为 false
。
关于java - 我如何知道上下文是 Activity 还是 IntentService?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31659905/