相关疑难解决方法(0)

实现AsyncQueryHandler

我正在尝试实现,AsyncQueryHandler因为我在此链接中遇到了同样的问题,但我没有看到任何关于实现它的示例或任何内容.

我试过了

AsyncQueryHandler handler = new AsyncQueryHandler(getContentResolver());
Run Code Online (Sandbox Code Playgroud)

因为这是构造函数在文档中显示的内容,但我得到一个错误cannot instantiate the type AsyncQueryHandler,说明如何使用它呢?

android android-handler

14
推荐指数
3
解决办法
1万
查看次数

进度对话框UI冻结/慢速

我有一个进度对话框,我在程序中使用了一个部分,我在后台进行了时间密集型操作,但是当对话框显示时,UI或微调器图标冻结/慢/犹豫使程序看起来好像冻结了一样.在我onPostExecute的我AsyncTask解雇对话.

为什么会发生这种情况,因为我在后台完成所有工作?

这是我的代码

pDialog = ProgressDialog.show(FullGame.this,"Starting New Game","Please Wait...", true);
new StartNewGame().execute(); 

    private class StartNewGame extends AsyncTask<Void,Void,Boolean>{

    @Override
    protected Boolean doInBackground(Void... params) {
        try{
            ContentValues values = new ContentValues();
            Cursor c = getContentResolver().query(Games.PART1_URI,new String[] {Games.PART1_NUM},
                    Games.PART1_GAME_ID+"="+gameID+" AND "+Games.PART1_FRAME_NUM+"="+10,null,null);
            c.moveToFirst();
            String num = c.getString(0);
            int part1 =0;
            if(num.equals("-")){
                part1=0;
            }else{
                part1=Integer.parseInt(num);
            }

            c = getContentResolver().query(Games.PART2_URI,new String[] {Games.PART2_NUM},
                    Games.PART2_GAME_ID+"="+gameID+" AND "+Games.PART2_FRAME_NUM+"="+10,null,null);
            c.moveToFirst();
            int part2 = 0;
            if(num.equals("-")){
                part2=0;
            }else{
                part2=Integer.parseInt(num);
            }

            c = getContentResolver().query(Games.PART3_URI,new String[] {Games.PART3_NUM},
                    Games.PART3_GAME_ID+"="+gameID,null,null);
            c.moveToFirst(); …
Run Code Online (Sandbox Code Playgroud)

android progressdialog

10
推荐指数
1
解决办法
8672
查看次数

运行和启动线程之间的区别

我不明白启动和运行线程之间的区别,我测试了两种方法并输出了相同的结果,首先我在同一个线程上使用了run()和start的组合,并且它们执行的功能如下:

public class TestRunAndStart implements Runnable {
public void run() {
    System.out.println("running");
}
public static void main(String[] args) {
     Thread t = new Thread(new TestRunAndStart());
     t.run();
     t.run();
     t.start(); 
}
Run Code Online (Sandbox Code Playgroud)

}

输出是:

running
running
running
Run Code Online (Sandbox Code Playgroud)

然后我看到run()方法的javadoc说: If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns 所以我尝试使用run()方法而没有单独的runnable,如下所示:

public class TestRun extends Thread {
public void run(){
    System.out.println("Running Normal Thread");
}
public static void main(String[]args){
    TestRun …
Run Code Online (Sandbox Code Playgroud)

java multithreading

7
推荐指数
2
解决办法
1万
查看次数