DBHelper中的AsyncTask选择?

时间:2015-03-09 11:31:23

标签: java android sqlite

我正在尝试让我的Android应用程序更高效,更快,所以我想让db调用异步(使用asynctask),但我无法弄清楚如何。 以下是我的代码段:

public List<POI> todosPOIs() {
    List<POI> POIs = new ArrayList<POI>();

    SQLiteDatabase db = getWritableDatabase();
    Cursor cursor = db.rawQuery("SELECT * FROM " + NOME_TABELA, null);

    if (cursor.moveToFirst()) {
        do {
            POIs.add(new POI(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4),cursor.getString(5),cursor.getString(6),cursor.getString(7),cursor.getString(8),cursor.getString(9),cursor.getString(10),cursor.getString(11)));
        }
        while (cursor.moveToNext());
    }
    cursor.close();
    db.close();
    return POIs;
}

编辑:

我已经按照你的说法完成了它的工作,但应用程序仍然很慢。我已启用strictmode所以我可以看到它为什么慢,这是我的logcat。任何虽然?? ??

03-12 09:07:02.385  28028-28028/roteiro.pap.pedro.roteiro D/StrictMode﹕ StrictMode policy violation; ~duration=29 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2
            at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1118)
            at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1038)
            at android.database.sqlite.SQLiteConnection.executeForLong(SQLiteConnection.java:592)
            at android.database.sqlite.SQLiteConnection.setPageSize(SQLiteConnection.java:244)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:213)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
            at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
            at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
            at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
            at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
            at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:972)
            at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
            at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
            at roteiro.pap.pedro.roteiro.DBHelper.todosPOIs(DBHelper.java:135)
            at roteiro.pap.pedro.roteiro.DBHelper$getData.doInBackground(DBHelper.java:128)
            at roteiro.pap.pedro.roteiro.DBHelper.getTodosPOIs(DBHelper.java:115)
            at roteiro.pap.pedro.roteiro.Lista.onCreate(Lista.java:60)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2446)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3953)
            at android.app.ActivityThread.access$700(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5434)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
03-12 09:07:02.385  28028-28028/roteiro.pap.pedro.roteiro D/StrictMode﹕ StrictMode policy violation; ~duration=28 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2
            at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1118)
            at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1038)
            at android.database.sqlite.SQLiteConnection.executeForLong(SQLiteConnection.java:592)
            at android.database.sqlite.SQLiteConnection.setForeignKeyModeFromConfiguration(SQLiteConnection.java:274)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:214)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
            at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
            at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
            at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
            at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
            at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:972)
            at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
            at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
            at roteiro.pap.pedro.roteiro.DBHelper.todosPOIs(DBHelper.java:135)
            at roteiro.pap.pedro.roteiro.DBHelper$getData.doInBackground(DBHelper.java:128)
            at roteiro.pap.pedro.roteiro.DBHelper.getTodosPOIs(DBHelper.java:115)
            at roteiro.pap.pedro.roteiro.Lista.onCreate(Lista.java:60)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2446)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3953)
            at android.app.ActivityThread.access$700(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5434)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
03-12 09:07:02.386  28028-28028/roteiro.pap.pedro.roteiro D/StrictMode﹕ StrictMode policy violation; ~duration=25 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2
            at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1118)
            at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1038)
            at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:635)
            at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:313)
            at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:287)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
            at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
            at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
            at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
            at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
            at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:972)
            at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
            at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
            at roteiro.pap.pedro.roteiro.DBHelper.todosPOIs(DBHelper.java:135)
            at roteiro.pap.pedro.roteiro.DBHelper$getData.doInBackground(DBHelper.java:128)
            at roteiro.pap.pedro.roteiro.DBHelper.getTodosPOIs(DBHelper.java:115)
            at roteiro.pap.pedro.roteiro.Lista.onCreate(Lista.java:60)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2446)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3953)
            at android.app.ActivityThread.access$700(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5434)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
03-12 09:07:02.386  28028-28028/roteiro.pap.pedro.roteiro D/StrictMode﹕ StrictMode policy violation; ~duration=23 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2
            at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1118)
            at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1038)
            at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:635)
            at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:316)
            at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:287)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
            at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
            at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
            at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
            at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
            at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:972)
            at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
            at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
            at roteiro.pap.pedro.roteiro.DBHelper.todosPOIs(DBHelper.java:135)
            at roteiro.pap.pedro.roteiro.DBHelper$getData.doInBackground(DBHelper.java:128)
            at roteiro.pap.pedro.roteiro.DBHelper.getTodosPOIs(DBHelper.java:115)
            at roteiro.pap.pedro.roteiro.Lista.onCreate(Lista.java:60)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2446)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3953)
            at android.app.ActivityThread.access$700(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5434)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
03-12 09:07:02.387  28028-28028/roteiro.pap.pedro.roteiro D/StrictMode﹕ StrictMode policy violation; ~duration=21 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2
            at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1118)
            at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1038)
            at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:635)
            at android.database.sqlite.SQLiteConnection.setSyncMode(SQLiteConnection.java:294)
            at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:288)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
            at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
            at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
            at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
            at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
            at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:972)
            at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
            at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
            at roteiro.pap.pedro.roteiro.DBHelper.todosPOIs(DBHelper.java:135)
            at roteiro.pap.pedro.roteiro.DBHelper$getData.doInBackground(DBHelper.java:128)
            at roteiro.pap.pedro.roteiro.DBHelper.getTodosPOIs(DBHelper.java:115)
            at roteiro.pap.pedro.roteiro.Lista.onCreate(Lista.java:60)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2446)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3953)
            at android.app.ActivityThread.access$700(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5434)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
03-12 09:07:02.388  28028-28028/roteiro.pap.pedro.roteiro D/StrictMode﹕ StrictMode policy violation; ~duration=19 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2
            at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1118)
            at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1038)
            at android.database.sqlite.SQLiteConnection.executeForLong(SQLiteConnection.java:592)
            at android.database.sqlite.SQLiteConnection.setJournalSizeLimit(SQLiteConnection.java:264)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:216)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
            at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
            at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
            at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
            at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
            at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:972)
            at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
            at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
            at roteiro.pap.pedro.roteiro.DBHelper.todosPOIs(DBHelper.java:135)
            at roteiro.pap.pedro.roteiro.DBHelper$getData.doInBackground(DBHelper.java:128)
            at roteiro.pap.pedro.roteiro.DBHelper.getTodosPOIs(DBHelper.java:115)
            at roteiro.pap.pedro.roteiro.Lista.onCreate(Lista.java:60)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2446)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3953)
            at android.app.ActivityThread.access$700(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5434)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
03-12 09:07:02.388  28028-28028/roteiro.pap.pedro.roteiro D/StrictMode﹕ StrictMode policy violation; ~duration=18 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2
            at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1118)
            at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1038)
            at android.database.sqlite.SQLiteConnection.executeForLong(SQLiteConnection.java:592)
            at android.database.sqlite.SQLiteConnection.setJournalSizeLimit(SQLiteConnection.java:266)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:216)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
            at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
            at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
            at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
            at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
            at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:972)
            at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
            at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
            at roteiro.pap.pedro.roteiro.DBHelper.todosPOIs(DBHelper.java:135)
            at roteiro.pap.pedro.roteiro.DBHelper$getData.doInBackground(DBHelper.java:128)
            at roteiro.pap.pedro.roteiro.DBHelper.getTodosPOIs(DBHelper.java:115)
            at roteiro.pap.pedro.roteiro.Lista.onCreate(Lista.java:60)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2446)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3953)
            at android.app.ActivityThread.access$700(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5434)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
03-12 09:07:02.389  28028-28028/roteiro.pap.pedro.roteiro D/StrictMode﹕ 

......

由于

1 个答案:

答案 0 :(得分:1)

您可以执行以下操作:

 private class getData extends AsyncTask<Void, Void, List<POI>>{
            @Override
            protected List<POI> doInBackground(Void... params) {
                return todosPOIs();
            }

            @Override
            protected void onPostExecute(List<POI> result) {
                if(result.size > 0){
                    //Do with the result whatever you want
                }
            }

并使用new getData().execute();执行此操作,无论您要将其称为async method