【问题标题】:about save Activity state [closed]关于保存活动状态[关闭]
【发布时间】:2012-06-19 08:55:38
【问题描述】:
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Init();
    backthread tr=new backthread();
    tr.execute(0,0,0);
}

backthread 是一个实现 AsyncTask 的类 当程序在 MainActivity 运行时,进度条的值将从 0 增加到 100(在后台更改其值),但是当我进入其他活动并返回时,进度条将从 0 重新启动到 100,我希望进度条的值继续增加当我进行其他活动并转身时;我该怎么办 ?

【问题讨论】:

    标签: android android-asynctask android-progressbar


    【解决方案1】:

    我认为您可以在 backthread 类的 currentUptae 中保留一个 int 变量,并在 onProgressUpdaete 中更新此变量。

    为 OnRestart 或 onStart 中的 currentUptae 变量创建 getter 和 setter 并更新进度条......

    【讨论】:

      【解决方案2】:

      在 doInBackground() 中你应该使用 publishProgress(progress++) 来更新进度结果和

         @Override
          protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
            tvInfo.setText("Downloaded " + values[0] + " files"); // progress bar 
          }
      

      【讨论】:

      • thanks.but 如果 AnsycTask 不是 MainActivity 中包含的类,我不知道如何使用该方法。
      猜你喜欢
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 1970-01-01
      相关资源
      最近更新 更多