AsyncTask and Objects

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

AsyncTask and Objects

Postby saphiroth » Thu Feb 25, 2010 8:49 am

Hello,
I have created an AsyncTask that queries a local database and inserts a cursor into an object, then this object is return.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. protected DataBaseQueryWrapper doInBackground(DataBaseQueryWrapper... wrapper) {
  3.  
  4.                 //publishProgress(Progress...);
  5.  
  6.                 try{
  7.  
  8.                         db = DataBaseHelper.getDBHelper(_context).getDatabase();
  9.  
  10.                         cursor = db.rawQuery(wrapper[0].getQuery(), null);
  11.  
  12.                        
  13.  
  14.                         wrapper[0].setCursor(cursor);
  15.  
  16.                
  17.  
  18.                         return wrapper[0];
  19.  
  20.                 }
  21.  
  22.                 catch(Exception e){
  23.  
  24.                         return wrapper[0];
  25.  
  26.                 }
  27.  
  28.  
  29.  
  30.         }
  31.  
  32.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


The application crashes when I hit the return statement and does not throw any exceptions. The DataBaseQueryWrapper class contains a String, int, and a Cursor with getters and setters for each. Would anyone know why this code would crash? Does the object have to be serializable in order to be passed back to the UI thread?

Thanks very much
saphiroth
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Oct 31, 2008 5:22 pm

Top

Cursor from AsyncTask

Postby saphiroth » Fri Feb 26, 2010 6:08 am

Well then, is it ok to return a Cursor object or perhaps an object that is not serializable from an AsyncTask?

Thanks very much
saphiroth
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Oct 31, 2008 5:22 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 3 guests