本文介绍了GetSystemService DOWNLOAD_SERVICE非活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的非活性类简单的方法,我使用code:

In my simple method in non activity class, I am using code:

mgr=(DownloadManager)mContext.getSystemService(DOWNLOAD_SERVICE); 

在非活动课,我的构造是这样的:

in non activity class, my constructor looks like:

public Download23(Context context){
    this.mContext=context;
}

但compilator不会接受DOWNLOAD_SERVICE字符串。你知道如何解决?

But compilator won't accept DOWNLOAD_SERVICE string. Do you know how to solve that?

推荐答案

但你可以传递活动到非活动类

but you can pass activity to a non activity class

Activityclass.java

Activityclass.java

public static Activity mAct;

onCreate()
{
mAct=this;
}

NonActivityclass.java

NonActivityclass.java

public Download23(){
    mgr=(DownloadManager)Activityclass.mAct.getSystemService(DOWNLOAD_SERVICE); 
}

希望你有我的意思

hope you got what i mean

这篇关于GetSystemService DOWNLOAD_SERVICE非活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 23:18