如何将受保护功能中的参数用于另一个受保护的功能?

时间:2016-08-04 09:19:39

标签: java android android-studio

我在protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); } 类中使用了MainActivity来使用其data作为用户进程的结果,并且我已经介绍了另一个用于显示ProgressDialog pd;的类 ---->>>>

 public class Loading
        extends AsyncTask<Void, Void, Void>
{
    public Loading() {}

    protected Void doInBackground(Void... paramVarArgs)
    {

///////某些私有函数需要来自onActivityResult的数据值/////////             ///////////////这里如何使用数据值//////////////             return null;         }

    protected void onPostExecute(Void paramVoid)
    {
        super.onPostExecute(paramVoid);
        MainActivity.this.pd.dismiss();

    }

    protected void onPreExecute()
    {
        super.onPreExecute();
        MainActivity.this.pd.setTitle("Loading App....");
        MainActivity.this.pd.setMessage("Please Wait.....");
        MainActivity.this.pd.show();
    }
}

现在我想将data protected void onActivityResult(int requestCode, int resultCode, Intent data)中的参数用作protected Void doInBackground(Void... paramVarArgs){} 我怎样才能做到这一点 ?感谢。

2 个答案:

答案 0 :(得分:0)

我得到了WOoW

AsyncTask Myasytsk = new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
    MainActivity.this.systemWritedo(pathfile);

    return null;
}
         protected void onPostExecute(Object result) {

             MainActivity.this.pd.dismiss();
             MainActivity.this.reboot();

         }

         protected void onPreExecute() {

             MainActivity.this.pd.setTitle("Installation....");
             MainActivity.this.pd.setMessage("Please Wait.....");
             MainActivity.this.pd.show();

         }
};
Myasytsk.execute();

答案 1 :(得分:0)

您的 AsyncTask类应该是这样的。

public class Loading extends AsyncTask<Void, Void, Void>
{
      private MainActivity act = null;

      //this is constructor
      public Loading(MainActicity _act) {
           this.act = _act;
      }
      protected Void doInBackground(Void... paramVarArgs)
      {
            //your codes
      }
      protected Void onPostExecute(Object result) {
           //your codes
           act.pd.dismiss();
           act.reboot();
      }
}

您可以在 MainActivity 中使用 AsyncTask类

private Loading loadingTask;
public ProgressDialog pd;    //your progress dialog must be public
private void DoSomething(){

                       //"this" send reference of MainActivity to Loading class
     loadingTask = new LoadingTask(this);
     loadingTask.execute(); 

}