Android studio不会在新主题中打印

时间:2018-03-27 16:47:51

标签: android android-studio

我正在尝试调试数据库进程,但Android studio似乎没有在新线程中向控制台打印语句。例如

            System.out.println("About to start new thread"); //this gets printed to the console

            new Thread(new Runnable() {
                public void run() {

                    ContactsDatabase db = ContactsDatabase.getContactsDatabase(getApplicationContext());
                    db.contactDao().insertAll(contact);
                    db.close();
                    System.out.println("Inside new thread"); //this doesn't get printed, why not?


                }
            });

我完全陷入困境。我做的事真的很蠢吗?

1 个答案:

答案 0 :(得分:1)

您需要在结尾处致电.start()

System.out.println("About to start new thread"); //this gets printed to the console
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Inside new thread"); //this doesn't get printed, why not?
            }
        }).start();