我有两项服务,其中一项使用传感器,另一项使用GPS。我有一个数据库。当我将它们组合起来时,我得到平均传感器值并将它们写成GPS线。为了获得平均值,我计算db。但一段时间后应用程序无法正常工作。它给出了这个错误。
Blockquote W / CursorWindow(2852):窗口已满:请求分配228个字节,可用空间156个字节,窗口大小2097152个字节 块引用
是否有可能清除缓存或其他内容?
答案 0 :(得分:0)
public class GPSDataContentProvider extends ContentProvider {
private static final String TAG = "GPSDataContentProvider";
public static final String DATABASE_NAME = "semgpsdata.db";
private static final int DATABASE_VERSION = 1;
public static final String POINT_TABLE_NAME = "gpspoints";
public static final String AUTHORITY = "com.semih";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/gpspoint");
private static final UriMatcher uriMatcher ;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(AUTHORITY, "gpspoint", DATABASE_VERSION);
}
/**
* This class helps open, create, and upgrade the database file.
*/
public static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
try {
Log.i(TAG, "Creating table " + POINT_TABLE_NAME);
db.execSQL("CREATE TABLE " + POINT_TABLE_NAME + " ("
+ GPSData.GPSPoint.KEY_ID + " INTEGER PRIMARY KEY,"
+ GPSData.GPSPoint.LATITUDE + " REAL,"
+ GPSData.GPSPoint.LONGITUDE + " REAL,"
+ GPSData.GPSPoint.PRESSURE + " DOUBLE,"
+ GPSData.GPSPoint.BHEIGHT + " REAL,"
+ GPSData.GPSPoint.TEMPERATURE + " REAL,"
+ GPSData.GPSPoint.HUMIDITY + " REAL,"
+ GPSData.GPSPoint.FLOOR + " REAL,"
+ GPSData.GPSPoint.ADDRESS + " REAL,"
+ GPSData.GPSPoint.PROVIDER + " REAL,"
+ GPSData.GPSPoint.SAT + " REAL,"
+ GPSData.GPSPoint.SPEED + " REAL,"
+ GPSData.GPSPoint.ACCURACY + " REAL,"
+ GPSData.GPSPoint.USER + " REAL,"
+ GPSData.GPSPoint.PHONE + " REAL,"
+ GPSData.GPSPoint.ESAY + " REAL,"
+ GPSData.GPSPoint.SAY + " REAL,"
+ GPSData.GPSPoint.KNTRL + " REAL,"
+ GPSData.GPSPoint.TIME + " INTEGER"
+ ");");
} catch (SQLiteException e) {
Log.e(TAG, e.toString());
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + POINT_TABLE_NAME);
onCreate(db);
}
public int getDbCount() {
String countQuery = "SELECT * FROM " + POINT_TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
int count = cursor.getCount();
cursor.close();
// return count
return count;
}
public void deleteDb(long id) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(POINT_TABLE_NAME, GPSData.GPSPoint.KEY_ID + " = ?",
new String[] { String.valueOf(id) });
}
public double getPressure (int rowID) {
double uname = 0;
SQLiteDatabase db = this.getReadableDatabase();
String where= GPSData.GPSPoint.KEY_ID + "=" + rowID;
String order = GPSData.GPSPoint.PRESSURE;
Cursor mCursor= db.query (POINT_TABLE_NAME, null, where, null, null, null,order);
while (mCursor.moveToNext()) {
uname = mCursor.getDouble(mCursor.getColumnIndex(GPSData.GPSPoint.PRESSURE));
}
mCursor.close();
return uname;
}
public double getBHeight (int rowID) {
double uname1 = 0;
SQLiteDatabase db = this.getReadableDatabase();
String where= GPSData.GPSPoint.KEY_ID + "=" + rowID;
String order = GPSData.GPSPoint.BHEIGHT;
Cursor mCursor= db.query (POINT_TABLE_NAME, null, where, null, null, null,order);
while (mCursor.moveToNext()) {
uname1 = mCursor.getDouble(mCursor.getColumnIndex(GPSData.GPSPoint.BHEIGHT));
}
mCursor.close();
return uname1;
}
public double getTemp (int rowID) {
double uname2 = 0;
SQLiteDatabase db = this.getReadableDatabase();
String where= GPSData.GPSPoint.KEY_ID + "=" + rowID;
String order = GPSData.GPSPoint.TEMPERATURE;
Cursor mCursor= db.query (POINT_TABLE_NAME, null, where, null, null, null,order);
while (mCursor.moveToNext()) {
uname2 = mCursor.getDouble(mCursor.getColumnIndex(GPSData.GPSPoint.TEMPERATURE));
}
mCursor.close();
return uname2;
}
public double getHumidity (int rowID) {
double uname3 = 0;
SQLiteDatabase db = this.getReadableDatabase();
String where= GPSData.GPSPoint.KEY_ID + "=" + rowID;
String order = GPSData.GPSPoint.HUMIDITY;
Cursor mCursor= db.query (POINT_TABLE_NAME, null, where, null, null, null,order);
while (mCursor.moveToNext()) {
uname3 = mCursor.getDouble(mCursor.getColumnIndex(GPSData.GPSPoint.HUMIDITY));
}
mCursor.close();
return uname3;
}
}
private DatabaseHelper mOpenHelper;
public boolean onCreate() {
mOpenHelper = new DatabaseHelper(getContext());
return true;
}
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getType(Uri uri) {
Log.i(TAG, "getting type for " + uri.toString());
// TODO Auto-generated method stub
return null;
}
@Override
public Uri insert(Uri uri, ContentValues values) {
Log.e(TAG, "inserting value " + values.toString());
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
long rowId = db.insert(POINT_TABLE_NAME, "", values);
if (rowId > 0) {
Uri noteUri = ContentUris.withAppendedId(GPSDataContentProvider.CONTENT_URI, rowId);
getContext().getContentResolver().notifyChange(noteUri, null);
return noteUri;
}
throw new SQLException("Failed to insert row into " + uri);
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
return null;
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
return 0;
}
}