i have view with canvas undo array(bitmap array), paint array, background bitmap, paths.
now i want to give functionality that user can save view as draft and can use anytime in future.
so how to store whole view locally in file or sqlite or sharedpreference?
The best way is to record all user input (by do this recording procedure in the "onTouch()" or "onGenericMovement()" methods/events) like touch coordinates, pressures, size of the "pen", etc...and then replicate them at runtime when you will have to display the draft again. Storing many undo_Bitmaps could be a waste of storage/database space and could take many seconds depending of the size of the display area.
I suggest to store all these informations in a BINARY file that is very fast during the reading/writing procedure.
When I often go back and forward in my learning-app (everytime loading the question and answer) i will get this error:
01-01 15:27:36.803: E/CursorWindow(3820): Could not allocate CursorWindow '/data/data/*package-name*/databases/quiz.db' of size 2097152 due to error -12.
I can't say exactly when I get this error, only that when im often changing the content
Can anybody help me to understand what this error means, please
Thanks
According to this question and answers you should check if you handle your cursors correctly and if the amount of data you query is too big (check the 2048k limit)
I've created a ListView populated by the data returned from a query.
It works, but in the LogCat I've got the message:
Cursor Window: Window is full: requested allocation 444 bytes, free space 363 bytes, window size 2097152 bytes
and it uses a couple of minutes for loading / visualizing the ListView.
My query returns about 3700 rows of String/Int/Double, each of which with 30 columns; no images or particular datatypes
What does this message exactly mean and how can I avoid it?
Can you improve performances by changing this Cursor Window?
From my experience this means that the query results are too large for the cursor's window and it requests more memory. Most times this request is honored, but on low end devices it could throw exceptions.
I don't know the specifics of the app in question but you referred to a ListView. A ListView cannot show 3700 rows at once and a endless list could help to load the data on demand
My advise is to break up the query into a multiple queries that return smaller results and close them before running the next query. After each successive query combine the results.
Short version:
After some investigation, it appears that this message is part of normal operation, and not a cause for concern. It is logged at the "Warning" level, but I think this is simply overeager.
Longer version:
This is (clearly labelled as) a "Windowed" cursor, which means that old records will be discarded as new records are obtained. In the simplest form, such a "window" implementation may contain up to N rows total, possibly with some read-ahead. In this implementation, however, the window size is defined instead by the total size. The number of rows kept in memory is instead based on how many would fit in the overall window, and will vary at runtime (This could perhaps be considered more of a "buffered" Cursor than "windowed" Cursor).
As a buffered implementation with a (soft-?)capped size, the earliest rows will be discarded only when the buffer is too full to accommodate the next row. In this case, 1 or more older rows are dropped. This "keep allocating rows as-needed until we can no longer have room for more, at which point we free up the oldest record(s) in our buffer and try again" process appears to be completely normal and expected, as a normal part of the process to keep the memory space confined.
I based this conclusion on reading the source here, combined with some inference:
https://android.googlesource.com/platform/frameworks/base/+/master/libs/androidfw/CursorWindow.cpp
Why are people talking about images and other massive LOBs?
If the size of a single row is larger than the entire "window" (buffer), then this strategy breaks down and you have an actual problem.
This was the message #op was getting:
Cursor Window: Window is full: requested allocation 444 bytes, free space 363 bytes, window size 2097152 bytes
This was the message #vovahost was getting:
CursorWindow: Window is full: requested allocation 2202504 bytes, free space 2076560 bytes, window size 2097152 bytes
In the first case, requested allocation is much smaller than the windows size. I expect that similar messages are issued repeatedly, with the same window size and varying requested allocation sizes. Each time this is printed, memory is freed from the larger window, and new allocations are made. This is normal and healthy operation.
In the second case, requested allocation size exceeds the overall window size. This is an actual problem, requiring storing and reading data in a more streamable way.
The difference is "length" (total number of rows) vs "width" (memory cost of the largest single row). The former (#tirrel's issue) is not an issue, but the latter (#vovahost's issue) is.
I also got this problem. In my case I saved a 2.2 MB image in database. When loading the data from the database using Cursor.getBlob() I would see this message in the Log:
CursorWindow: Window is full: requested allocation 2202504 bytes, free space 2076560 bytes, window size 2097152 bytes
After I would get this message if I try to retrieve any data (String, number, etc) for successive rows it is returned as null without any errors.
The solution was to remove the 2.2 MB blob. I don't know if it's possible to load bigger blobs from database in Android.
Also, note that changing the window has overhead of IPC.
So, if the cursor has large number of items and is used with a listview, fast navigation results in change of window and hence frequent IPCs. This might result in ANR if the system is loaded.
I would like to know please how to get my database(which is off course *.sqlite file) size in bytes?
My current way to do it(which isn't working) is:
new File(DataManager.getInstance().db.getPath()).length()
but I'm just getting here the same number every time 53,676~ , which is irrelevant to the database's content, I'm getting this number even when it's empty.
Thank you.
OK the solution is pretty simple, my recent way to check the database file was good.
But I didn't take in account that greenDao adds to the database another 53 KB. So an empty DB size would be 53± KB and after some insertions it would get bigger and bigger.
i am working with an greeting card application in which all the things are static and user have to just select greetings.
so suggest me how to work with it there is 3 options i have like:
1)put text file in asset folder which is having all the data
2)database
3)string-array
database should include
id
name
image
title
greeting
textstyle
textsize
frames
--but this will take too much memory allocation because there are 20 greetings.
any kind of suggestions are valuable for me.
Don't try to insert image as blob into database, because it requires to much memory, please keep the image path name, retrieve it from database and load the image.
Keep the greetings image in application database directory...
This is the suggestion to avoiding OutOfMemory exception. Try to load one by one.
And before loading the image into memory, always keep one thing in your mind that the image should not be too much large, if it is large then compress it and then load..