我怎么知道上下文是Activity还是IntentService?

时间:2015-07-27 17:50:30

标签: java android multithreading android-intent android-asynctask

我在变量中有上下文,我怎么知道上下文是否是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

我需要将httpClient用于IntentService,但是我在UI线程中使用了相同的函数,需要AsynkTask。

1 个答案:

答案 0 :(得分:0)

在Java中,使用instanceof运算符来确定对象是否是某个类或接口的实例。因此,如果context instanceof IntentServicetrue(或context的某个子类),IntentService的实例,则IntentService将为false