English 中文(简体)
我怎么能够制造第2线透镜,有进步的方言和pa子?
原标题:How can I create a 2nd thread, have progressdialog and pause the main thread?

索里,我是新安纳的节目。 我有一个Xml parser,我不希望穿透社。 我只想展示一种进步的辩词,而教区则自行运行,但我不想让主人开始下一次活动,直到教区完成。 我有手法,但进步方言全时显示。 为了取代休庭期间,我对教区进行了同样的审判。 此外,我想避免时间上的.。 感谢任何帮助。

我的手法,随后是实施“ the”的那类。 可操作:

private void parseGasStationData() {
        gasStations = null;
        StationParser sp = new StationParser(activity);
        Thread parserThread = new Thread(sp);
        parserThread.start();
        while (parserThread.isAlive()) {
            // do nothing
        }
        gasStations = sp.getList();
        Log.v("Parser-Status", "xml parsed successfully: "
                + (gasStations != null));
    }

public class StationParser implements Runnable {
    private Activity activity;
    private final ProgressDialog pd;

    public StationParser(Activity activity) {
        this.activity = activity;
        pd = ProgressDialog.show(activity, "", "Parsing data...", true, false);
    }

    @Override
    public void run() {
        try {
            runParser();
        } catch (XmlPullParserException e) {
            Log.e("Parser-Error", "XmlPullParserException", e);
            e.printStackTrace();
        } catch (IOException e) {
            Log.e("Parser-Error", "IOException", e);
            e.printStackTrace();
        } catch (ParseException e) {
            Log.e("Parser-Error", "ParseException", e);
            e.printStackTrace();
        }
        pd.dismiss();
    }
问题回答

我们使用<代码>AsyncTask的类别,使背景业务显示出成果。 See the main document page here 第一个例子似乎对你非常有用,只是修改了<条形码>。

该法典:

while (parserThread.isAlive()) {
    // do nothing
}

needs to go. As long as you have that, you might as well not be using a separate thread at all. (In fact, it s worse, because it s a "busy wait" that hogs the CPU.)

这样做的正确方法是背靠呼吁。 当修饰时,可以打电话post(Runnable),在“ID”透镜上操作一个过程,使进步方言消失。 您可使用





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签