我要将当前活动的引用传递给一个不扩展活动的类的方法。 我需要将此引用用于活动活动, 这样我就可以使用 getWindow (). addFlags (LayoutParams. FLAG_KEP_SCREEN_ON);
我将当前上下文和活动都传送到类对象, 使用这些设置器方法在类中 :
public class VersionCheck {
public Context context;
public Activity activity;
//---------------------------------------------------------------------------------------------------------
//set the current context
//---------------------------------------------------------------------------------------------------------
public void setContext(Context context) {
this.context = context;
}
//---------------------------------------------------------------------------------------------------------
//set the current activity
//---------------------------------------------------------------------------------------------------------
public void setActivity(Activity activity) {
this.activity = activity;
}
AsyncTashsk 在类中使用活动参考(摘录如下):
//---------------------------------------------------------------------------------------------------------
//asynchronous task to check if there is a newer version of the app available
//---------------------------------------------------------------------------------------------------------
private class UpdateCheckTask extends AsyncTask<String, Void, String> {
HttpClient httpclient;
HttpPost httppost;
HttpResponse response;
InputStream inputStream;
byte[] data;
StringBuffer buffer;
protected void onPreExecute ()
{
VersionCheck vc = new VersionCheck();
//do not lock screen or drop connection to server on login
activity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
//initiate progress dialogue to block user input during initial data retrieval
ProcessingDialog = ProgressDialog.show(context, "Please Wait", "Checking for Updates", true,false);
}
@Override
protected String doInBackground(String... currentVersion)
{
如何引用“ 活动” 来将它传递到“ 活动” 设定的“ 活动” 方法? 我使用“ 活动” 方法来引用“ 活动 ”? 我用我的“ 活动” 方法作为上下文的引用。 “ 活动” 是否同样?