Android onHandleIntent不处理数据库查询

时间:2014-10-19 22:57:49

标签: android sqlite android-intent

在设备启动时,我想从SQLite数据库中获取一些值。我使用BroadcastReceiver在启动时成功启动了IntentService,并打印出它已启动。当我进入onHandleIntent并运行查询时,它不会打印出数据库查询。

IntentService(再次,它成功启动):

public class QueuedService extends IntentService
{
    SharedPreferences sharedPrefs; 
    DBHelper dbHelper; 
    Context context; 

    public QueuedService() 
    {
        super("QueuedService");
    }

    @Override
    public void onCreate()
    {
        super.onCreate();
    }

    public int onStartCommand(Intent intent, int flags, int startId)
    { 
        super.onStartCommand(intent, flags, startId); 
        Log.v("QueuedService", "Received start id " + startId + " : " + intent); 

        return START_STICKY; 
    }

    @Override
    protected void onHandleIntent(Intent intent) 
    {
        Log.v("QueuedService", "Started Service"); // THIS prints

        context = getApplicationContext(); 
        dbHelper = new DBHelper(context);

        List<QueuePostTwitter> qTwit = dbHelper.getQueueTwitter(); 
        Log.v("QueuedService", Integer.toString(qTwit.size())); // this doesn't print ?
    }
}

BroadcastReceiver:

public class AutostartReceiver extends BroadcastReceiver
{

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction()))
        {
            Intent backgroundService = new Intent(context, StartBackgroundSyncService.class);       
            context.startService(backgroundService);

            Intent queuedService = new Intent(context, QueuedService.class); 
            context.startService(queuedService); 
        }
    }
}

0 个答案:

没有答案