Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:AsycTask赢得';不要调用ProgressUpdate_Android_Android Asynctask - Fatal编程技术网

Android 安卓:AsycTask赢得';不要调用ProgressUpdate

Android 安卓:AsycTask赢得';不要调用ProgressUpdate,android,android-asynctask,Android,Android Asynctask,因此,我创建了一个AsyncTask类,它成功地运行了doInBackground()。我已经调试了它,整个doInBackground()方法运行正常: public class MyClass extends AsyncTask<String , String , Boolean> { protected Boolean doInBackground(String... strings) { ArrayList<String[]> stories = new

因此,我创建了一个
AsyncTask
类,它成功地运行了
doInBackground()
。我已经调试了它,整个
doInBackground()
方法运行正常:

public class MyClass extends AsyncTask<String , String , Boolean> {
protected Boolean doInBackground(String... strings)
{
    ArrayList<String[]> stories = new ArrayList<String[]>();

    ...*irrelevant code that works*...

    String[][] storiesA = new String[stories.size()][2];

    ...*irrelevant code that works*...

    ArrayList<Integer> displayed = new ArrayList<Integer>();

    //calls publishProgress() every 10 seconds with a random String[2] from storiesA
    for (int x = 0 ; x < storiesA.length ; x++)
    {
        if (displayed.size() >= storiesA.length) displayed.clear();
        Random gen = new Random();
        int rand;
        rand = gen.nextInt(storiesA.length);
        while (displayed.contains(rand))
        {
            rand = gen.nextInt(storiesA.length);
        }
        displayed.add(rand);
        publishProgress(storiesA[rand][0] , storiesA[rand][1]);
        long t0 , t1;
        t0=System.currentTimeMillis();
        do
        {
            t1=System.currentTimeMillis();
        } while (t1-t0<10000);
    }

    return true;

}
}
如果相关,我还定义了:

protected void onPostExecute(Boolean result) {
    //will never call this method; it is deprecated in this context
    TextView title = (TextView)findViewById(R.id.bulletinBoardTitle);
    TextView body = (TextView)findViewById(R.id.bulletinBoardText);
    title.setText("Refreshing...");
    body.setText("Murica!");
}
因此,我运行的所有调试器的问题都很明显。而整个
doInBackground()
代码(在此处执行:)

当调用
publishProcess()
时,
onProgressUpdate()
方法永远不会运行,运行良好

我是一个非常新手的Android程序员,所以请记住,如果你有任何想法可能是什么问题在这里


谢谢你的帮助

您是否检查了storiesA.length>0?你的意思是调用了publishProcess(),但没有调用onProgressUpdate()?你确定onProgressUpdate覆盖了AsyncTask方法吗1)doInBackground()方法高亮显示(在调试中),因此假设调用了publishProcess(),但onProgressUpdate()从未启动。2)我使用的方法,逐字逐句,is:protected void onProgressUpdate(字符串…故事)解决了它。我认为,既然onProgressUpdate()方法从doInBackground()中获取了内容,那么它应该在我的活动中。相反,我意识到(感谢James Andresakis),这些方法覆盖了AsyncTask()方法。因此,由于我需要更新文本框,我创建了Media(我的活动)类型的doInBackground()参数,在调用doInBackground()时将该实例保存到一个局部变量“Media”,然后调用它来更新文本框:TextView title=(TextView)((活动)Media);
protected void onPostExecute(Boolean result) {
    //will never call this method; it is deprecated in this context
    TextView title = (TextView)findViewById(R.id.bulletinBoardTitle);
    TextView body = (TextView)findViewById(R.id.bulletinBoardText);
    title.setText("Refreshing...");
    body.setText("Murica!");
}
protected void onCreate(Bundle savedInstanceState)  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.media);

    new MyClass().execute();


}