Fix for OutofMemoryError: bitmap size exceeds VM budget

by haric zhu » Thu, 17 Jun 2010 13:48:08 GMT


Sponsored Links
 Because the memory of cell phone is very limited, so when you are operating
a bitmap it will take too much resource, it is no perfect way to avoid, the
only thing you can do is to optimize it, like more bigger sample size, maybe
options.inSampleSize = 10, or adjust the value of height and width, then
remember  to release memory in time. *

*
2010/6/16 pawan nimje <pawanni...@gmail.com>

>



Other Threads

1. Intent-filter to handle *.foo.zip but avoid handling other zips

Hi,

I believe I have figured things out correctly, but I would appreciate
input of others to avoid breaking things.

I'm hoping to setup my app to be able to download files such as
Gingerbread.wltheme.zip from any website and be handled with my app.
However I do not want my app to be used for normal Zip files as it's
only meant to handle these special wltheme type of zip files. I'd like
to use the .wltheme.zip filename as it makes it easy on webservers to
send the mime type correctly and it makes it easy for users to extract
the files and manually edit them. (Renaming files on Windows is a lot
more difficult than it should be).

On Gingerbread I can get away with:
        <activity android:name=".UserThemeInstaller"
android:theme="@android:style/Theme.Dialog">
                    <intent-filter>
                        <action android:name="android.intent.action.VIEW" />
                        <category 
android:name="android.intent.category.DEFAULT" />
                        <data
                          android:mimeType="application/zip"
                          android:scheme="file"
                          android:host="*"
                          android:pathPattern=".*\\.wltheme\\.zip" />
                    </intent-filter>
                </activity>

As the Download app will let you download a zip file and then when
opening from there lets my app handle it.

However for Android 2.1/2.2 it seems the file won't even download
without a generic handler for application/zip, so the above only works
if the user also has Astro or similar installed. I found that this
seems to work:
        <activity android:name=".UserThemeInstaller"
android:theme="@android:style/Theme.Dialog">
                    <intent-filter>
                        <action android:name="android.intent.action.VIEW" />
                        <category 
android:name="android.intent.category.DEFAULT" />
                        <data
                          android:mimeType="application/zip"
                          android:scheme="file"
                          android:host="*"
                          android:pathPattern=".*\\.wltheme\\.zip" />
                    </intent-filter>
                    <intent-filter android:priority="-100" >
                <action android:name="android.intent.action.VIEW" />
                <category
android:name="android.intent.category.DEFAULT" />
                <data
                  android:mimeType="application/zip"
                  android:scheme="file" />
            </intent-filter>
                </activity>

Where if the user only has my app installed then they download
a .wltheme.zip and it is allowed because of the handler for
application/zip. This also doesn't annoy the user much as if they
download a normal .zip and do have Astro or similar it won't try to
get them to open it with my app as the priority for the generic zip is
very low.
Worst case is if they user only has my app and downloads a normal zip,
then my app will try to handle it and present an error message. This
seems acceptable.

My question is, am I doing this correctly or is it likely to break
something?

Thanks,
-Kevin

-- 

2. Webview crashes on select box or any Dialog

I have an application where clicking on an item in a list shows
webview with javascript injected.I need to save the webview object so
that when the user presses the same item again the existing webview is
shown instead of reloading it and injecting the javascript again.I am
able to save the webview object in Arraylist of webview inside the
application class.

I check whether the item already exists in the Arraylist and if it do
exists take the corresponding object and set the object as the content
of the activity as shown below.

 temp_WebView=new WebView(this);
     temp_WebView=(WebView)application.getWebview(j);
     ViewGroup parent = (ViewGroup)
application.getWebview(j).getParent();
     parent.removeView(application.getWebview(j));
     setContentView(temp_WebView);

This works fine but when clicking on any of the select box inside the
webview where a dialog is populated it gets crashed  with the
following error,


WARN/WindowManager(60): Attempted to add application window with
unknown token HistoryRecord{4506d1e8 tabviewapp.com/.Webresults}.
Aborting.

 DEBUG/AndroidRuntime(500): Shutting down VM

 WARN/dalvikvm(500): threadid=1: thread exiting with uncaught
exception (group=0x4001d800)
 ERROR/AndroidRuntime(500): FATAL EXCEPTION: main
 ERROR/AndroidRuntime(500): android.view.WindowManager
$BadTokenException: Unable to  add window -- token
android.os.BinderProxy@45034510 is not valid; is your activity
running?
 ERROR/AndroidRuntime(500): at
android.view.ViewRoot.setView(ViewRoot.java:505)
 ERROR/AndroidRuntime(500): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)

 ERROR/AndroidRuntime(500):  at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)

 ERROR/AndroidRuntime(500):     at android.view.Window
$LocalWindowManager.addView(Window.java:424)

 ERROR/AndroidRuntime(500):     at android.app.Dialog.show(Dialog.java:
241)

 ERROR/AndroidRuntime(500):     at android.webkit.WebView
$InvokeListBox.run(WebView.java:7095)

 ERROR/AndroidRuntime(500):     at
android.os.Handler.handleCallback(Handler.java:587)

 ERROR/AndroidRuntime(500):     at
android.os.Handler.dispatchMessage(Handler.java:92)

 ERROR/AndroidRuntime(500):     at android.os.Looper.loop(Looper.java:
123)

 ERROR/AndroidRuntime(500):     at
android.app.ActivityThread.main(ActivityThread.java:4627)

 ERROR/AndroidRuntime(500):     at
java.lang.reflect.Method.invokeNative(Native Method)

 ERROR/AndroidRuntime(500):     at
java.lang.reflect.Method.invoke(Method.java:521)

 ERROR/AndroidRuntime(500):     at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)

 ERROR/AndroidRuntime(500):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

 ERROR/AndroidRuntime(500):     at
dalvik.system.NativeStart.main(Native Method)

 WARN/ActivityManager(60):   Force finishing activity
tabviewapp.com/.Webresults


I think the problem is with the context of the webview but not able to
figure out how to set the context for the existing object or pass
context to dialog generated inside the webview.

Thanks in advance.

-- 

3. lcd 18bpp problem

4. How to input the multiple keyboard inputs

5. Strange thing, using HorizontalScrollView

6. Android education program

7. code to invoke Android Music Player Application