Android :: Optimizing Bitmap Loading By Using ASyncTask

Aug 4, 2010

I have been trying to optimize my single thread app which loads a bunch of tiles that makeup a large bitmap.The app was becoming very sluggish when it would load the new tiles into system memory.I'm now looking trying to use Async Tasks for this purpose. The app detects which tile is in the top left in a method called by onDraw, creates a string that contains the path of the bitmap in the Assets folder, and then checks to see if the bitmap is null before drawing. If it is null, it will load it into memory. My idea was to process the bitmap in DoBackground, and in postExecute trigger a view invalidate to display the async loaded bitmap. Few questions:

1.) can i execute my aSync task for each bitmap? (this statement: new myAsyncTaskManager().execute(bitmapPath); if not, what is the best way to go about it since the only thing aSync will do is just load bitmaps into memory?

2.) Is it possible to set the priority aSyncTask if the bitmaps load too slow?

3.) Is there a better way to go about this? im certain it is the bitmap loading, and not the canvas drawing that slows down the app.

My temporary aSync code:

private class myAsyncTaskManager extends AsyncTask<String, Void, String> {

@Override
protected String doInBackground(String... bitmapPath) {
Log.e("sys","i ran using aTask");
try {

bitmapArray[rectBeingDrawn] = BitmapFactory.decodeStream(assetManager.open(imagePathToLoad));

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} return null;
}

@Override
protected void onPostExecute(String result) {
// execution of result of Long time consuming operation
mCampusMap.invalidate()

Android :: Optimizing bitmap loading by using aSyncTask


Android :: Loading A Resource To A Mutable Bitmap

Sep 11, 2010

I am loading a bitmap from a resource like so:

Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image);

What I want to do is make some changes to the bitmap before It gets drawn to the main canvas in my draw method (As it would seem wasteful to repeat lots of drawing in my main loop when it isn't going to change). I am making the changes to the bitmap with the following:

Canvas c = new Canvas(mBackground);
c.drawARGB(...); // etc

So naturally I get an exception

java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor

So to avoid that I made a copy of the bitmap so that it is mutable

Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image).copy(Bitmap.Config.ARGB_8888, true);

Which avoid the problem however it sometimes causes OutOfMemoryExceptions, do know any better ways of achieving what I want?

View 2 Replies View Related

Android :: Loading An Alpha Mask Bitmap

Oct 28, 2010

I have a single-channel PNG file I'd like to use as an alpha mask for Porter-Duff drawing operations.If I load it without any options, the resulting Bitmap has an RGB_565 config, i.e. treated as grayscale.If I set the preferred config to ALPHA_8, it loads it as a grayscale ARGB_8888 instead.How can I convince Android to treat this file as an alpha mask instead of a grayscale image?

mask1 = BitmapFactory.decodeStream(pngStream);
// mask1.getConfig() is now RGB_565

BitmapFactory.Options maskOpts = new BitmapFactory.Options();
maskOpts.inPreferredConfig = Bitmap.Config.ALPHA_8;
mask2 = BitmapFactory.decodeStream(pngStream, null, maskOpts);
// mask2.getConfig() is now ARGB_8888 (the alpha channel is fully opaque)

View 1 Replies View Related

Android :: OutOfMemory Exception When Loading Bitmap From External Storage

Nov 5, 2010

In my application I load a couple of images from JPEG and PNG files. When I place all those files into assets directory and load it in this way, everything is ok:

CODE:..................

But when I try to load the exact same images from sd card, I get an OutOfMemory exception!

CODE:..............

This is what I get in the log:

CODE:...........

UPDATE: Tried both of these on real device - it seems that I can't load more than 12MB of bitmaps into whatever is called "external memory" (this is not an sd card).

View 7 Replies View Related

Android :: Loading Only Part Of Bitmap File In Android

Mar 30, 2010

I would like to load a cropped version of a bitmap image into a Bitmap object, without loading the original bitmap as well. Is this at all possible without writing custom loading routines to handle the raw data?

View 1 Replies View Related

Android :: Instance Variable Of Activity Not Being Set OnPostExecute Of AsyncTask - Return Data From AsyncTask

Jul 28, 2010

I'm trying to figure out the correct way to create an AsyncTask to retrieve some data from the internet and then to take that data and bundle it up in an Intent and pass it to a new activity(A list display). So in the first activity I just have an EditText and Button. In the event of an OnClick the task should be called and when it is finished the data should be bundled inside an Intent and passed to the next Activity. The problem is when I take the results from onPostExecute and set them to an instance variable of the main activity, that instance variable is still null when the task is complete. Here is the barebones version of the code:

CODE:...........

When I debug the application I see onPostExecute does contain a valid PlacesList full of results, so why is the instance variable places set to null after the task is executed? I am going about "returning data" from an AsyncTask incorrectly?

View 1 Replies View Related

Android :: Optimizing Very Big Switch?

Mar 26, 2009

I have switch with 255 cases in my project - DroidGear... How i could optimize it?

View 6 Replies View Related

Android : Crop Bitmap Without Reading Entire Bitmap / Cannot Read Image Into Memory

Jul 21, 2010

I have a very large image and I only want to display a section the size of the display (no scaling), and the section should just be the center of the image. Because the image is very large I cannot read the entire image into memory and then crop it. This is what I have so far but it will give OutOfMemory for large images. Also I don't think inSampleSize applies because I want to crop the image, not lower the resolution.

Uri data = getIntent().getData();
Input Stream is = getContentResolver().openInputStream(data);
Bitmap bitmap = BitmapFactory.decodeStream(is, null, null);

Any help would be great?

View 3 Replies View Related

Android :: Create Mutable Bitmap From Camera - Draw Another Bitmap On Top - And Save It

Apr 2, 2009

I am 1) taking a picture and 2) then draw another Bitmap on top of it 3) then I store it

I am doing it as follows and it works on the emulator.

On the device I get a OutOfMemoryError: bitmap size exceeds VM budget android.graphics.Bitmap.nativeCopy(Native Method) android.graphics.Bitmap.copy(Bitmap.java:199) in the line copy the Bitmap to get a mutable Bitmap.

CODE:...........

What I am asking:

a) Is there a better way to do what I am doing? 1) take a picture 2) draw another Bitmap on top of it 3) then I store it

b) What is the best way to create a mutable Bitmap from the picture I just took with the camera?

In my app, resolution is not an issue. If it works better for small photos that would be fine.

View 3 Replies View Related

Android :: Optimizing Image Processing Algorithms

Aug 19, 2010

I am developing a mobile application that involves complex image processing operations. The app is designed in Java while the core image processing ops are implemented in native code, and compiled using the Android NDK.Now, I know that native code will *not* yield any significant performance improvement over Java code, and that the NDK purpose is only to support re-use of code libs (or to quickly integrate legacy code).are there any resources/tips-n-tricks/white papers/ samples on optimizing image processing algorithms for Android? To be even more specific, I am looking out for optimizing memory operations (cache misses, memory stalls, etc.). I profiled my application code and came to the conclusion that memory issues are causing the *maximum* performance penalty. (Nothing surprising over there, it is expected, but just verified with profile data as well).

View 1 Replies View Related

Android : Way For Optimizing List View Scroll?

Aug 26, 2010

I have list view with fairly complex list view items consisting of several image views, several text views, progress bars, etc. Depending on the state of the item some of these elements can be show and some are hidden. I understand that listview recycles views. Right now I am dealing with slow listview scrolling especially on lower powered devices. What's the best way to deal with this problem?

I already optimized each list item view as much as I could. Now I am facing with what's the best? Use one single view with many children for all items and hide and show various children depending on the item state. This way I do not inflate each item view as list is being scrolled but need to show and hide constantly various child views.

Another approach is to build item view dynamically each time view is requested in the adapter getView method. In this case I can only add at run time those elements that are truly needed for current item state but this requires inflating item view every time.

Finally the third approach is most extreme is to have one custom view and draw everything myself. This of cause requires a lot of work.

View 7 Replies View Related

Android :: Tips For Optimizing A Website For Droid's Browser?

Feb 14, 2009

I'm looking for tips, tricks and resources on optimizing a website design for Android's browser.

I'm building an Android app and some of the functionality will be accessible through a web interface.

View 7 Replies View Related

Android :: Overlay Bitmap - Draw Over A Bitmap

Oct 8, 2009

I have two questions actually:

Is it better to draw an image on a bitmap or create a bitmap as resource and then draw it over a bitmap? Performance wise... which one is better?

If I want to draw something transparent over a bitmap, how would I go about doing it?

If I want to overlay one transparent bitmap over another, how would I do it?

View 1 Replies View Related

Android :: Draw A Bitmap Rotated Onto Another Bitmap

Mar 22, 2009

My goal is the draw a bitmap onto another bitmap but rotated 90 degress. whats the most efficient way to do that. My current method is as follows which is horribly bad because it creates a new bitmap every time.

CODE:.....................

View 4 Replies View Related

General :: Optimizing Apps For Tablets?

Mar 18, 2013

Who can optimize apps for tablets.

GT-N8013

View 2 Replies View Related

General :: LG Not Optimizing Software Properly

Feb 15, 2012

I have the Optimus 2X, which seems to struggle playing flash videos that are higher than 480p, yet the Motorola Atrix which also uses the Tegra 2 SoC manages to play 720p flash videos smoothly.

Could this be caused by LG not optimizing the software properly? Would a custom ROM possibly fix this problem?

View 7 Replies View Related

HTC Droid Eris :: Optimizing Gmail Storage Space

Aug 10, 2010

Without going crazy, I've searched the forums and haven't found many topics to address this. Apologies in advance if such topics, in face, exist.I've had my Eris for nine months, and I've never really messed with the Gmail app/storage settings much. But I'm noticing that it's taking up around 50MB of storage on the phone. I have it set to sync 2 days. I have five labels that get synced. My Inbox, and one other label, are set to "Sync all;" the other three labels are set to "Sync 2 days."Any time I try to change the settings or how many days to sync (like changing everything to 2 days, or 1 day), it winds up eating more of my phone's internal storage, but for an app to use a third of the total storage seems a bit extreme to me. My Gmail app is showing 332KB, of which, 52KB is data and 280KB is the app. There is no option to clear the cache. I can Manage Space or Clear Data, though. My Gmail storage is showing 49.89MB, of which, 276KB is the application. There is no option to clear the cache or manage space, only clear the data.Also, while I'm on the topic, is there any reason for the discrepancy between how much space the Market says a given app occupies, versus what the phone says? Example: The Market says Maps uses 4MB, or so. My phone shows it occupying twice that much space. Facebook is allegedly 1.5MB in size, but it takes up four times as much space on the phone. There is no cache to clear, and I have everything disabled that can be disabled. What's using up so much space in these apps?

View 5 Replies View Related

Samsung Fascinate : How To Use Autokiller Correctly / Optimizing System To Get More Battery

Nov 29, 2010

How does one use Autokiller correctly? I want to make sure I'm optimizing my system to get even more battery than I am. Typically I pull over 24 hours on a charge. Want to see if I can get over two days. Thanks in advance Nitsuj17 and Saps =P

View 5 Replies View Related

Android :: Displaying A Now Loading Image While Applic - Loading

May 4, 2009

I want to display a fancy 'loading' image at my app's startup time.

The problem: my startup code is mostly GUI related, hence needs to run on UI thread.

Is there a way to do both - that is run UI-related code on UI thread while an image is displayed to the user?

View 8 Replies View Related

Android :: Draw Shape Or Bitmap Into Another Bitmap - Java - Android

Jun 22, 2010

I want to draw a shape(many circles particularly) into a Specific Bitmap. I have never used canvas / 2D graphs etc. As i see it i create a Drawable put the bitmap in it then "canvas-it" to the shapes i want etc.

View 1 Replies View Related

Android :: Loading Activity Darkens Screen - Loading Screen

Nov 2, 2009

I've looked through the documentation and I can't seem to figure out how to have the screen blured/greyed when I select an activity that may take a while to load.

This seems to be an Android standard (both the Camera app and the Camcorder app do it when first selected), but I don't see any documentation on it. I even tried looking through the source of these apps on git, but couldn't seem to find it.

View 3 Replies View Related

Android :: Threads Or ASyncTask

Apr 6, 2010

I am working on a simple application (studying purposes) which list all the files from a selected folder. On top of that I would like to have a search feature where the user can search for files (the code for that is already in place). Now, I was thinking about having the search running in the background somehow, whilst the user can still navigate, create folders, copy, sort and do other stuffs normally. When the search finishes the user would get a notification and then could click on it and go to that activity (It ideally should be the same ListView I already use for browsing the files, I would just need to update the Adapter there with the latest processed data after clicking in the notification). What's the best answer for that? Threading or AsyncTask?

View 4 Replies View Related

Android :: AsyncTask And Queries

Dec 27, 2009

Can anyone point me to a good example where a AsyncTask queries a local SQLite database and then updates the UI successfully. I have a database which I query using doInBackground... create a new custom SimpleCursorAdapter (overriding onViewBind), return the adapter (SimpleCursorAdapter), then in postExecute() create ListView adapter which is set to the the SimpleCursorAdapter, that was returned, then I set the listview adapter using SetAdapter(adapter);...

For some reason I throw an exception on fillWindow.java:200....

View 2 Replies View Related

Android :: AsyncTask On A Button

Jul 15, 2009

My application parse an xml file dans display data in a list view. On start of application i load data using an AsyncTask. A Progress Dialog is display during the load. This part works fine.A button in the application make it possible to reload the data. I would like to run the AsyncTask but the sytem say i can't alter view in other thread. I have also read an AsyncTask can't be run another time So i would like to know what is the best way to do this and not to have the "application not responding" message.

View 5 Replies View Related

Android :: AsyncTask And UI Activity

Aug 9, 2010

I know this is not how an async task should behave but my question is how to "block" the user while executing it.My need is the following: I have my own backup/restore process and I have an async task to run these two actions. The backup is fine, I can warn the user when the backup is done and that's just fine But my problem is about the restore process. When the user click on restore he shouldn't be able to make any change in the application (and anyway don't want to because he would lose all his changes).I understand that having the user blocked while restoring (or maybe with a progress bar) is not a best pratice but I do not see any other possibility in this context.

View 7 Replies View Related

Android :: Timing Out An AsyncTask?

Apr 9, 2010

I know how to use AsyncTask in a standard manner to manage operations that are in the background in relation to a UI thread.However,I want to run a task in the background which might run for a very long time under certain circumstances. In these cases, I would like to force the background task to fail if it runs for an excessive amount of time.I know that I can invoke the "get(long timeout, TimeUnit unit)" method of AsyncTask in my UI thread in order to terminate my background task if it runs too long. However, in that case, my UI will block while this "get()" command is waiting.There are probably other drawbacks to directly calling "get()" in this manner, not the least of which being an evil interaction with the "done()" method of AsyncTask's contained FutureTask object, which itself is calling "get()" at least this is what I see when I look at the source code for AsyncTask.

View 10 Replies View Related

Android :: ViewSwitcher With AsyncTask

Jul 5, 2010

I have an activity that needs to do some stuff in the background. When the background is done, I want it to load a new activity.I can successfully kick off the async task and using using ViewSwitcher I can show a nice progress dialog.However, when the user hit 'back' or 'close' from the new task, I want them to see the main screen of this task again. So, I use the showPrevious() after I start the new Activity, but I see the screen switch from the loading window back to the main window BEFORE the new Acitivity is launched.How do I get it to switch after the new activity, or when they come back from the new activity?I tried onRestart() and onResume() but both of them seem to give me a view of -1 that I couldn't do much with.

View 2 Replies View Related

Android :: Timing An ASyncTask

Sep 20, 2010

I'm running a network service within an ASyncTask. I want to be able to time the task, and after a certain period of time interrupt it.Is there a simple way to do this? Basically, when the doInBackground() methods starts, I want to say "If it hasn't completed in 30 seconds, do something else".

View 2 Replies View Related

Android :: How To Use AsyncTask From Thread?

Jul 29, 2009

I'm developing a game based on SurfaceView and a game thread for the whole game thing.Now I want to do some HTTP requests triggered on events inside the thread. They should of course be asynchronous, so the game doesn't stop. I found AsyncTask to be a neat way to do this but I'm having trouble implementing this at the moment. Maybe I misunderstood the concept of AsyncTask,I don't know it just drives me nuts as I read docs and blogs and still I don't get it. So sorry if that's a dumb question but I'm mad of thinking about it.

View 4 Replies View Related

Android :: Asynctask Threads Never End

Mar 13, 2010

while debugging and app that uses AsyncTask to record audio and update UI I noticed that everytime that an AsyncTask object ends running (finishes doInBackground and onPostExecute or on Cancelled it´s thread stays alive (running status).At least for me that should not be the behavior of the class since the doInBackground task may not stay running forever (as an example the android manual says that a status bar should be updated by an asynctask, and it won´t last for the whole app running time).Is there anything I´m missing, as a method to destroy it, or should I just ignore and keep creating threads as I need and the VM will handle them as it needs resources?

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved